コード例 #1
0
    def __init__(self,
                 server_url=None,
                 application_id=None,
                 application_secret=None,
                 application_url=None):
        if server_url:
            self.server_url = server_url
        if application_id:
            self.application_id = application_id
        if application_secret:
            self.application_secret = application_secret
        if application_url:
            self.application_url = application_url

        resource_url = self.server_url
        authorize_url = urlparse.urljoin(self.server_url, '/oauth/authorize')
        token_url = urlparse.urljoin(self.server_url, '/oauth/token')
        self.redirect_uri = urlparse.urljoin(self.application_url, '/callback')

        self.sanction_client = sanction.Client(
            auth_endpoint=authorize_url,
            token_endpoint=token_url,
            resource_endpoint=resource_url,
            client_id=self.application_id,
            client_secret=self.application_secret)
コード例 #2
0
    def _request(self, url, json_data=None, retry=2):
        if self._oauth_client is None:
            self._oauth_client = sanction.Client(token_endpoint=API_URL +
                                                 '/auth/token')

        if self._oauth_client.access_token is None:
            self._oauth_client.request_token(grant_type='password',
                                             username=self._account_id,
                                             password=self._password)

        headers = {
            "Authorization": f"Bearer {self._oauth_client.access_token}"
        }
        response = None
        try:
            if json_data:
                response = requests.post(url, json=json_data, headers=headers)
            else:
                response = requests.get(url, headers=headers)
        except Exception:
            _LOGGER.error("Failed to connect to adax", exc_info=True)
            if retry < 1:
                raise
        if (response is None or response.status_code >= 300) and retry > 0:
            self._oauth_client = None
            return self._request(url, json_data, retry=retry - 1)
        return response
コード例 #3
0
    def access(self):
        """
        Simply connect to yahoo API to get token and store in pickle.
        :return: Returns the auth object
        """
        # instantiating a client to process OAuth2 response
        c = sanction.Client(auth_endpoint=self.all_creds['auth_uri'],
                            token_endpoint=self.all_creds['token_uri'],
                            client_id=self.all_creds['consumer_key'],
                            client_secret=self.all_creds['consumer_secret'])

        # Authorize and get the token
        auth_uri_r = c.auth_uri(redirect_uri=self.all_creds['callback_url'])
        webbrowser.open(auth_uri_r)
        auth_code = raw_input('Enter the auth code: ')

        # Grab the Token
        c.request_token(redirect_uri='oob', code=auth_code)

        # Store the Token Details
        print 'Storing tokens in {}...'.format(PKL_NAME)
        with open(PKL_NAME, 'wb') as f:
            pickle.dump(c, f)

        return c
コード例 #4
0
ファイル: oauth2.py プロジェクト: zozo123/buildbot
        def thd(
        ):  # everything in deferToThread is not counted with trial  --coverage :-(
            c = sanction.Client(token_endpoint=self.tokenUri,
                                client_id=self.clientId,
                                **self.tokenConfig)
            c.request_token(code=code, redirect_uri=self.loginUri)

            return self.getUserInfoFromOAuthClient(c)
コード例 #5
0
    def __init__(
        self,
        client_id,
        client_secret,
        scope="browse feed message note stash user user.manage comment.post collection"
    ):
        self.client_id = client_id
        self.client_secret = client_secret

        self.auth_endpoint = "https://www.deviantart.com/oauth2/authorize"
        self.token_endpoint = "https://www.deviantart.com/oauth2/token"
        self.resource_endpoint = "https://www.deviantart.com/api/v1/oauth2"

        self.oauth = sanction.Client(
            auth_endpoint=self.auth_endpoint,
            token_endpoint=self.token_endpoint,
            resource_endpoint=self.resource_endpoint,
            client_id=self.client_id,
            client_secret=self.client_secret,
        )

        self.auth()
コード例 #6
0
ファイル: oauth2.py プロジェクト: zozo123/buildbot
 def thd():
     c = sanction.Client(auth_endpoint=self.authUri,
                         client_id=self.clientId)
     return c.auth_uri(redirect_uri=self.loginUri, **self.authUriConfig)