auth.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:buildnumber.io 作者: ldiqual 项目源码 文件源码
def authenticate(self, request):

        token_from_get = request.GET.get('token', None)
        token_from_headers = self._token_from_request_headers(request)

        if token_from_get:
            token = token_from_get
        elif token_from_headers:
            token = token_from_headers
        else:
            msg = "You must provide an API token to use this server. " \
                "You can add `?token=API_TOKEN` at the end of the URL, or use a basic HTTP authentication where user=API_TOKEN with an empty password. " \
                "Please check your emails for your API token."
            raise exceptions.AuthenticationFailed(msg)

        # Grab the API key model, make sure it exists
        try:
            api_key = ApiKey.objects.get(key=token)
        except ApiKey.DoesNotExist:
            raise exceptions.AuthenticationFailed("This API token doesn't exist")

        return (api_key.account, None)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号