コード例 #1
0
 def test_request_access_token_failure(self):
     error_message = {'error_reason': 'authorization not given'}
     response = requests.Response()
     response.status_code = requests.codes.conflict
     response._content = json.dumps(error_message)
     self.replacer.replace('requests.post',
                           lambda *args, **kwargs: response)
     call = lambda: token_utils.request_access_token(
         'myid', 'mysecret', 'theauthcode', 'http://oauth.org/2/authorize')
     self.assertRaises(token_utils.TokenRequestError, call)
コード例 #2
0
 def test_request_access_token_failure(self):
     error_message = {
                 'error_reason': 'authorization not given'
             }
     response = requests.Response()
     response.status_code = requests.codes.conflict
     response._content = json.dumps(error_message)
     self.replacer.replace('requests.post', lambda *args, **kwargs: response)
     call = lambda: token_utils.request_access_token('myid',
             'mysecret','theauthcode', 'http://oauth.org/2/authorize')
     self.assertRaises(token_utils.TokenRequestError, call)
コード例 #3
0
    def get_access_token_from_code(self, code):
        """
        After receiving a code from the end user, this method will acquire an
        access token from the server which can be used for subsequent requests.

        :param code: The code which the user received after authenticating with the server and authorizing the client.

        :return: Tuple containing (access_token, refresh_token, expire_time)
        """
        url_parts = ('https', self.server, '/goauth/token', None, None)
        result = token_utils.request_access_token(
            self.api_key, self.api_secret, code,
            urlparse.urlunsplit(url_parts))
        return (result.access_token, result.refresh_token,
                time.mktime(datetime.utcnow().timetuple()) + result.expires_in)
コード例 #4
0
ファイル: client.py プロジェクト: kbase/auth_service
    def get_access_token_from_code(self, code):
        """
        After receiving a code from the end user, this method will acquire an
        access token from the server which can be used for subsequent requests.

        :param code: The code which the user received after authenticating with the server and authorizing the client.

        :return: Tuple containing (access_token, refresh_token, expire_time)
        """
        url_parts = ('https', self.server, '/goauth/token', None, None)
        result = token_utils.request_access_token(self.client,
                self.client_secret, code, urlparse.urlunsplit(url_parts))
        return (
                result.access_token,
                result.refresh_token,
                time.mktime(datetime.utcnow().timetuple()) + result.expires_in
                )
コード例 #5
0
    def goauth_get_access_token_from_code(self, code, redirect_uri=None):
        """
        After receiving a code from the end user, this method will acquire an
        access token from the server which can be used for subsequent requests.

        :param code: The code which the user received after authenticating with the server and authorizing the client.
        :param redirect_uri: The redirect URI which will be used for token
        exchange. Per OAuth2 spec, this must be passed here.

        :return: Tuple containing (access_token, refresh_token, expire_time)
        """
        url_parts = ('https', self.server, '/goauth/token', None, None)
        result = token_utils.request_access_token(
            self.client,
            self.client_secret,
            code,
            urlparse.urlunsplit(url_parts),
            redirect_uri=redirect_uri)
        return (result.access_token, result.refresh_token,
                time.mktime(datetime.utcnow().timetuple()) + result.expires_in)
コード例 #6
0
 def test_request_access_token(self):
     response = requests.Response()
     response.status_code = requests.codes.ok
     access_token = {
             "access_token": "faohwefadfawaw",
             "refresh_token": "fhajhkjbhrafw",
             "expires_in": 123456789,
             "token_type": "Bearer"
             }
     response._content = json.dumps(access_token)
     self.replacer.replace('requests.post', lambda *args, **kwargs: response)
     token_map = token_utils.request_access_token('myid',
             'mysecret','theauthcode', 'http://oauth.org/2/authorize')
     self.assertEqual('faohwefadfawaw', token_map['access_token'])
     self.assertEqual('faohwefadfawaw', token_map.access_token)
     self.assertEqual('fhajhkjbhrafw', token_map['refresh_token'])
     self.assertEqual('fhajhkjbhrafw', token_map.refresh_token)
     self.assertEqual(123456789, token_map['expires_in'])
     self.assertEqual(123456789, token_map.expires_in)
     self.assertEqual('Bearer', token_map['token_type'])
     self.assertEqual('Bearer', token_map.token_type)
コード例 #7
0
 def test_request_access_token(self):
     response = requests.Response()
     response.status_code = requests.codes.created
     access_token = {
         "access_token": "faohwefadfawaw",
         "refresh_token": "fhajhkjbhrafw",
         "expires_in": 123456789,
         "token_type": "Bearer"
     }
     response._content = json.dumps(access_token)
     self.replacer.replace('requests.post',
                           lambda *args, **kwargs: response)
     token_map = token_utils.request_access_token(
         'myid', 'mysecret', 'theauthcode', 'http://oauth.org/2/authorize')
     self.assertEqual('faohwefadfawaw', token_map['access_token'])
     self.assertEqual('faohwefadfawaw', token_map.access_token)
     self.assertEqual('fhajhkjbhrafw', token_map['refresh_token'])
     self.assertEqual('fhajhkjbhrafw', token_map.refresh_token)
     self.assertEqual(123456789, token_map['expires_in'])
     self.assertEqual(123456789, token_map.expires_in)
     self.assertEqual('Bearer', token_map['token_type'])
     self.assertEqual('Bearer', token_map.token_type)