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


Python oauth2.BackendApplicationClient方法代码示例

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


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

示例1: get_nebula_client

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import BackendApplicationClient [as 别名]
def get_nebula_client(client_id, client_secret, account_id, use_ssl):
    client_scope = ["read", "write", "execute"]
    headers = {"x-mwb-clientid": client_id,
               "x-mwb-accountid": account_id}

    client = BackendApplicationClient(client_id, scope=client_scope)
    nebula = OAuth2Session(client=client, scope=client_scope)
    nebula.headers.update(headers)
    token = nebula.fetch_token(
        token_url=nebula_url('/oauth2/token'),
        client_secret=client_secret, scope=client_scope,
        verify=use_ssl
    )

    return "Bearer " + token.get('access_token')


# Test connectivity to the Nebula cloud 
开发者ID:demisto,项目名称:content,代码行数:20,代码来源:Malwarebytes.py

示例2: initialize_api_client

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import BackendApplicationClient [as 别名]
def initialize_api_client(self):
        """
            Initialize OAuth2Session client depending on client credentials flow or authorization grant flow
        """
        if self.code is None:
            # client credentials flow
            self.api_client = OAuth2Session(self.client_id, client=BackendApplicationClient(self.client_id),
                                            token=self.token)
        else:
            # authorization grant flow
            refresh_url = self.token_url if self.auto_refresh else None
            self.api_client = OAuth2Session(self.client_id, redirect_uri=self.redirect_uri, scope=self.scope,
                                            auto_refresh_url=refresh_url, token_updater=self.token_refresh_callback,
                                            auto_refresh_kwargs={
                                                'client_id': self.client_id,
                                                'client_secret': self.client_secret}) 
开发者ID:pokitdok,项目名称:pokitdok-python,代码行数:18,代码来源:client.py

示例3: _connect

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import BackendApplicationClient [as 别名]
def _connect(self):
        """
        Retrieve token from USMA API and create an authenticated session
        :returns OAuth2Session: authenticated client session
        """
        oauth_client = BackendApplicationClient(client_id=self.client_id)
        oauth_session = OAuth2Session(client=oauth_client)
        token = oauth_session.fetch_token(token_url=self.url + "oauth/token",
                                            client_id=self.client_id,
                                            client_secret=self.client_secret)
                                            #verify=False)
        return OAuth2Session(client_id=self.client_id,
                                    token=token) 
开发者ID:graphistry,项目名称:pygraphistry,代码行数:15,代码来源:unimatrix.py

示例4: _fetch_token

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import BackendApplicationClient [as 别名]
def _fetch_token(self, request):
        """ Collects a new token from Sentinel Hub service
        """
        oauth_client = BackendApplicationClient(client_id=self.config.sh_client_id)

        LOGGER.debug('Creating a new authentication session with Sentinel Hub service')
        with OAuth2Session(client=oauth_client) as oauth_session:
            return oauth_session.fetch_token(
                token_url=request.url,
                client_id=self.config.sh_client_id,
                client_secret=self.config.sh_client_secret
            ) 
开发者ID:sentinel-hub,项目名称:sentinelhub-py,代码行数:14,代码来源:sentinelhub_session.py

示例5: __init__

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

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

示例6: get_token

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import BackendApplicationClient [as 别名]
def get_token():
    client = BackendApplicationClient(client_id=settings.SOCIAL_AUTH_OPENSTAX_KEY)
    oauth = OAuth2Session(client=client)
    token = oauth.fetch_token(token_url=settings.ACCESS_TOKEN_URL,
                              client_id=settings.SOCIAL_AUTH_OPENSTAX_KEY,
                              client_secret=settings.SOCIAL_AUTH_OPENSTAX_SECRET)

    return token 
开发者ID:openstax,项目名称:openstax-cms,代码行数:10,代码来源:functions.py

示例7: create_oauth2_session

# 需要导入模块: from oauthlib import oauth2 [as 别名]
# 或者: from oauthlib.oauth2 import BackendApplicationClient [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


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