当前位置: 首页>>代码示例>>Python>>正文


Python oauth2.WebApplicationClient方法代码示例

本文整理汇总了Python中oauthlib.oauth2.WebApplicationClient方法的典型用法代码示例。如果您正苦于以下问题:Python oauth2.WebApplicationClient方法的具体用法?Python oauth2.WebApplicationClient怎么用?Python oauth2.WebApplicationClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauthlib.oauth2的用法示例。


在下文中一共展示了oauth2.WebApplicationClient方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def __init__(self, credentials):
        self.credentials = credentials
        self.token = {
            'access_token': credentials.access_token,
            'refresh_token': credentials.refresh_token,
            'token_type': credentials.token_type,
            'expires_in': str(int(credentials.token_expiry) - ts()),
        }
        oauth_client = WebApplicationClient(credentials.client_id,
            token=self.token, default_token_placement='query')
        self.client = OAuth2Session(
            credentials.client_id,
            token=self.token,
            client=oauth_client,
            auto_refresh_url='{}/oauth2/token'.format(NokiaAuth.URL),
            auto_refresh_kwargs={
                'client_id': credentials.client_id,
                'client_secret': credentials.consumer_secret,
            },
            token_updater=self.set_token
        ) 
开发者ID:magnific0,项目名称:nokia-weight-sync,代码行数:23,代码来源:nokia.py

示例2: get_token

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def get_token(client_id, client_secret, ads_code):
  """ Using authentication code retrieved from URL, take code, client_id and
  client_secret to send HTTP request to fetch refresh token taken from parsed
  response """

  oauthlib_client = oauth2.WebApplicationClient(client_id)
  # Prepare the access token request body --> makes a
  # request to the token endpoint by adding the following parameters
  post_body = oauthlib_client.prepare_request_body(
      client_secret=client_secret, code=ads_code, redirect_uri=CALLBACK_URL)
  # URL request
  request = urllib2.Request(GOOGLE_OAUTH2_GEN_ENDPOINT,
                            post_body, OAUTH2_REFRESH_HEADERS)
  if HTTPS_PROXY:
    request.set_proxy(HTTPS_PROXY, 'https')
  # Open the given url, read and decode into raw_response
  raw_response = urllib2.urlopen(request).read().decode()
  # Parse the JSON response body given in raw_response
  oauth2_credentials = oauthlib_client.parse_request_body_response(
      raw_response)
  # Return the refresh token
  token = oauth2_credentials['refresh_token']

  return token 
开发者ID:google,项目名称:crmint,代码行数:26,代码来源:ads_auth_code.py

示例3: __init__

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def __init__(self, mendeley, state):
        MendeleyLoginAuthenticator.__init__(self, mendeley, WebApplicationClient(mendeley.client_id), state)

        self.token_url = self.mendeley.host + '/oauth/token'
        self.auth = HTTPBasicAuth(self.mendeley.client_id, self.mendeley.client_secret) 
开发者ID:Mendeley,项目名称:mendeley-python-sdk,代码行数:7,代码来源:auth.py

示例4: __init__

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def __init__(
        self,
        credentials: Credentials,
        refresh_cb: Optional[Callable[[Credentials], None]] = None,
    ):
        """Initialize new object."""
        self._credentials = credentials
        self._refresh_cb: Final = refresh_cb
        token: Final = {
            "access_token": credentials.access_token,
            "refresh_token": credentials.refresh_token,
            "token_type": credentials.token_type,
            "expires_in": str(int(credentials.token_expiry) - arrow.utcnow().timestamp),
        }

        self._client: Final = OAuth2Session(
            credentials.client_id,
            token=token,
            client=WebApplicationClient(  # nosec
                credentials.client_id, token=token, default_token_placement="query"
            ),
            auto_refresh_url="%s/%s" % (WithingsAuth.URL, WithingsAuth.PATH_TOKEN),
            auto_refresh_kwargs={
                "client_id": credentials.client_id,
                "client_secret": credentials.consumer_secret,
            },
            token_updater=self._update_token,
        ) 
开发者ID:vangorra,项目名称:python_withings_api,代码行数:30,代码来源:__init__.py

示例5: __init__

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def __init__(self, client_id=None, client=None, token=None):
        """Construct a new OAuth 2 authorization object.

        :param client_id: Client id obtained during registration
        :param client: :class:`oauthlib.oauth2.Client` to be used. Default is
                       WebApplicationClient which is useful for any
                       hosted application but not mobile or desktop.
        :param token: Token dictionary, must include access_token
                      and token_type.
        """
        self._client = client or WebApplicationClient(client_id, token=token)
        if token:
            for k, v in token.items():
                setattr(self._client, k, v) 
开发者ID:kylebebak,项目名称:Requester,代码行数:16,代码来源:oauth2_auth.py

示例6: get_url

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def get_url(client_id):
  """ Create oauth client and use this to generate the URL to get the authorisation
  code using client_id """

  oauthlib_client = oauth2.WebApplicationClient(client_id)
  # This is the URL construction for getting the authorisation code
  authorize_url = oauthlib_client.prepare_request_uri(
      GOOGLE_OAUTH2_AUTH_ENDPOINT, redirect_uri=CALLBACK_URL, scope=SCOPE)

  return authorize_url 
开发者ID:google,项目名称:crmint,代码行数:12,代码来源:ads_auth_code.py

示例7: create_oauth2_session

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def create_oauth2_session(self):
        if self.auth_type != OAUTH2:
            raise ValueError('Auth type must be %r for credentials type OAuth2Credentials' % OAUTH2)

        has_token = False
        scope = ['https://outlook.office365.com/.default']
        session_params = {}
        token_params = {}

        if isinstance(self.credentials, OAuth2AuthorizationCodeCredentials):
            # Ask for a refresh token
            scope.append('offline_access')

            # We don't know (or need) the Microsoft tenant ID. Use
            # common/ to let Microsoft select the appropriate tenant
            # for the provided authorization code or refresh token.
            #
            # Suppress looks-like-password warning from Bandit.
            token_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'  # nosec

            client_params = {}
            has_token = self.credentials.access_token is not None
            if has_token:
                session_params['token'] = self.credentials.access_token
            elif self.credentials.authorization_code is not None:
                token_params['code'] = self.credentials.authorization_code
                self.credentials.authorization_code = None

            if self.credentials.client_id is not None and self.credentials.client_secret is not None:
                # If we're given a client ID and secret, we have enough
                # to refresh access tokens ourselves. In other cases the
                # session will raise TokenExpiredError and we'll need to
                # ask the calling application to refresh the token (that
                # covers cases where the caller doesn't have access to
                # the client secret but is working with a service that
                # can provide it refreshed tokens on a limited basis).
                session_params.update({
                    'auto_refresh_kwargs': {
                        'client_id': self.credentials.client_id,
                        'client_secret': self.credentials.client_secret,
                    },
                    'auto_refresh_url': token_url,
                    'token_updater': self.credentials.on_token_auto_refreshed,
                })
            client = WebApplicationClient(self.credentials.client_id, **client_params)
        else:
            token_url = 'https://login.microsoftonline.com/%s/oauth2/v2.0/token' % self.credentials.tenant_id
            client = BackendApplicationClient(client_id=self.credentials.client_id)

        session = self.raw_session(oauth2_client=client, oauth2_session_params=session_params)
        if not has_token:
            # Fetch the token explicitly -- it doesn't occur implicitly
            token = session.fetch_token(token_url=token_url, client_id=self.credentials.client_id,
                                        client_secret=self.credentials.client_secret, scope=scope,
                                        **token_params)
            # Allow the credentials object to update its copy of the new
            # token, and give the application an opportunity to cache it
            self.credentials.on_token_auto_refreshed(token)
        session.auth = get_auth_instance(auth_type=OAUTH2, client=client)

        return session 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:63,代码来源:protocol.py

示例8: __init__

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def __init__(self, client_id=None, client=None, auto_refresh_url=None,
            auto_refresh_kwargs=None, scope=None, redirect_uri=None, token=None,
            state=None, token_updater=None, **kwargs):
        """Construct a new OAuth 2 client session.

        :param client_id: Client id obtained during registration
        :param client: :class:`oauthlib.oauth2.Client` to be used. Default is
                       WebApplicationClient which is useful for any
                       hosted application but not mobile or desktop.
        :param scope: List of scopes you wish to request access to
        :param redirect_uri: Redirect URI you registered as callback
        :param token: Token dictionary, must include access_token
                      and token_type.
        :param state: State string used to prevent CSRF. This will be given
                      when creating the authorization url and must be supplied
                      when parsing the authorization response.
                      Can be either a string or a no argument callable.
        :auto_refresh_url: Refresh token endpoint URL, must be HTTPS. Supply
                           this if you wish the client to automatically refresh
                           your access tokens.
        :auto_refresh_kwargs: Extra arguments to pass to the refresh token
                              endpoint.
        :token_updater: Method with one argument, token, to be used to update
                        your token database on automatic token refresh. If not
                        set a TokenUpdated warning will be raised when a token
                        has been refreshed. This warning will carry the token
                        in its token argument.
        :param kwargs: Arguments to pass to the Session constructor.
        """
        super(OAuth2Session, self).__init__(**kwargs)
        self._client = client or WebApplicationClient(client_id, token=token)
        self.token = token or {}
        self.scope = scope
        self.redirect_uri = redirect_uri
        self.state = state or generate_token
        self._state = state
        self.auto_refresh_url = auto_refresh_url
        self.auto_refresh_kwargs = auto_refresh_kwargs or {}
        self.token_updater = token_updater

        # Allow customizations for non compliant providers through various
        # hooks to adjust requests and responses.
        self.compliance_hook = {
            'access_token_response': set(),
            'refresh_token_response': set(),
            'protected_request': set(),
        } 
开发者ID:kylebebak,项目名称:Requester,代码行数:49,代码来源:oauth2_session.py

示例9: __init__

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import WebApplicationClient [as 别名]
def __init__(self, client_id=None, client=None, auto_refresh_url=None,
            auto_refresh_kwargs=None, scope=None, redirect_uri=None, token=None,
            state=None, token_updater=None, **kwargs):
        """Construct a new OAuth 2 client session.

        :param client_id: Client id obtained during registration
        :param client: :class:`oauthlib.oauth2.Client` to be used. Default is
                       WebApplicationClient which is useful for any
                       hosted application but not mobile or desktop.
        :param scope: List of scopes you wish to request access to
        :param redirect_uri: Redirect URI you registered as callback
        :param token: Token dictionary, must include access_token
                      and token_type.
        :param state: State string used to prevent CSRF. This will be given
                      when creating the authorization url and must be supplied
                      when parsing the authorization response.
                      Can be either a string or a no argument callable.
        :auto_refresh_url: Refresh token endpoint URL, must be HTTPS. Supply
                           this if you wish the client to automatically refresh
                           your access tokens.
        :auto_refresh_kwargs: Extra arguments to pass to the refresh token
                              endpoint.
        :token_updater: Method with one argument, token, to be used to update
                        your token databse on automatic token refresh. If not
                        set a TokenUpdated warning will be raised when a token
                        has been refreshed. This warning will carry the token
                        in its token argument.
        :param kwargs: Arguments to pass to the Session constructor.
        """
        super(OAuth2Session, self).__init__(**kwargs)
        self._client = client or WebApplicationClient(client_id, token=token)
        self.token = token or {}
        self.scope = scope
        self.redirect_uri = redirect_uri
        self.state = state or generate_token
        self._state = state
        self.auto_refresh_url = auto_refresh_url
        self.auto_refresh_kwargs = auto_refresh_kwargs or {}
        self.token_updater = token_updater

        # Allow customizations for non compliant providers through various
        # hooks to adjust requests and responses.
        self.compliance_hook = {
            'access_token_response': set([]),
            'refresh_token_response': set([]),
            'protected_request': set([]),
        } 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:49,代码来源:oauth2_session.py


注:本文中的oauthlib.oauth2.WebApplicationClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。