gauth.py 文件源码

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

项目:gdata-python3 作者: dvska 项目源码 文件源码
def generate_authorize_url(self, redirect_uri='urn:ietf:wg:oauth:2.0:oob',
                               response_type='code', access_type='offline',
                               approval_prompt='auto', **kwargs):
        """Returns a URI to redirect to the provider.

        Args:
          redirect_uri: Either the string 'urn:ietf:wg:oauth:2.0:oob' for a
                        non-web-based application, or a URI that handles the
                        callback from the authorization server.
          response_type: Either the string 'code' for server-side or native
                         application, or the string 'token' for client-side
                         application.
          access_type: Either the string 'offline' to request a refresh token or
                       'online'.
          approval_prompt: Either the string 'auto' to let the OAuth mechanism
                           determine if the approval page is needed or 'force'
                           if the approval prompt is desired in all cases.

        If redirect_uri is 'urn:ietf:wg:oauth:2.0:oob' then pass in the
        generated verification code to get_access_token,
        otherwise pass in the query parameters received
        at the callback uri to get_access_token.
        If the response_type is 'token', no need to call
        get_access_token as the API will return it within
        the query parameters received at the callback:
          oauth2_token.access_token = YOUR_ACCESS_TOKEN
        """
        self.redirect_uri = redirect_uri
        query = {
            'response_type': response_type,
            'client_id': self.client_id,
            'redirect_uri': redirect_uri,
            'scope': self.scope,
            'approval_prompt': approval_prompt,
            'access_type': access_type
        }
        query.update(kwargs)
        parts = list(urllib.parse.urlparse(self.auth_uri))
        query.update(dict(parse_qsl(parts[4])))  # 4 is the index of the query part
        parts[4] = urllib.parse.urlencode(query)
        return urllib.parse.urlunparse(parts)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号