Example #1
0
    def test_2nd_refresh_token_parse_response(self):
        request_args = {'grant_type': 'client_credentials'}
        _srv = self.entity.client_get("service",'accesstoken')
        _request_info = _srv.get_request_parameters(request_args=request_args)

        response = AccessTokenResponse(**{
            "access_token": "2YotnFZFEjr1zCsicMWpAA",
            "token_type": "example",
            "expires_in": 3600,
            "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
            "example_parameter": "example_value"
        })

        _response = _srv.parse_response(response.to_json(), sformat="json")
        # since no state attribute is involved, a key is minted
        _key = rndstr(16)
        _srv.update_service_context(_response, key=_key)
        info = _srv.client_get("service_context").state.get_item(AccessTokenResponse, 'token_response', _key)
        assert '__expires_at' in info

        # Move from token to refresh token service

        _srv = self.entity.client_get("service",'refresh_token')
        _request_info = _srv.get_request_parameters(request_args=request_args, state=_key)

        refresh_response = AccessTokenResponse(**{
            "access_token": 'wy4R01DmMoB5xkI65nNkVv1l',
            "token_type": "example",
            "expires_in": 3600,
            "refresh_token": 'lhNX9LSG8w1QuD6tSgc6CPfJ',
        })

        _response = _srv.parse_response(refresh_response.to_json(), sformat="json")
        _srv.update_service_context(_response, key=_key)
        info = _srv.client_get("service_context").state.get_item(AccessTokenResponse, 'token_response', _key)
        assert '__expires_at' in info

        _request_info = _srv.get_request_parameters(request_args=request_args, state=_key)
        assert _request_info['headers'] == {
            'Authorization': 'Bearer {}'.format(refresh_response["refresh_token"]),
            'Content-Type': 'application/x-www-form-urlencoded'
        }
Example #2
0
 def create_service(self):
     client_config = {
         'client_id': 'client_id',
         'client_secret': 'a longesh password',
         'redirect_uris': ['https://example.com/cli/authz_cb']
     }
     service_context = ServiceContext(config=client_config)
     db = InMemoryStateDataBase()
     auth_response = AuthorizationResponse(code='access_code')
     token_response = AccessTokenResponse(access_token='bearer_token',
                                          refresh_token='refresh')
     _state = State(auth_response=auth_response.to_json(),
                    token_response=token_response.to_json())
     db.set('abcdef', _state.to_json())
     self.service = service_factory('RefreshAccessToken', ['oauth2'],
                                    state_db=db,
                                    service_context=service_context)
     self.service.endpoint = 'https://example.com/token'
    def test_do_userinfo_request_init(self):
        auth_request = AuthorizationRequest(
            redirect_uri='https://example.com/cli/authz_cb', state='state')
        auth_response = AuthorizationResponse(code='access_code')
        token_response = AccessTokenResponse(refresh_token="refresh_with_me",
                                             access_token="access")
        _state = State(auth_response=auth_response.to_json(),
                       auth_request=auth_request.to_json(),
                       token_response=token_response.to_json())

        self.client.state_db.set('ABCDE', _state.to_json())

        _srv = self.client.service['userinfo']
        _srv.endpoint = "https://example.com/userinfo"
        _info = _srv.get_request_parameters(state='ABCDE')
        assert _info
        assert _info['headers'] == {'Authorization': 'Bearer access'}
        assert _info['url'] == 'https://example.com/userinfo'
Example #4
0
    def test_token_parse_response(self):
        request_args = {'grant_type': 'client_credentials'}
        _srv = self.entity.client_get("service",'accesstoken')
        _request_info = _srv.get_request_parameters(request_args=request_args)

        response = AccessTokenResponse(**{
            "access_token": "2YotnFZFEjr1zCsicMWpAA",
            "token_type": "example",
            "expires_in": 3600,
            "refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
            "example_parameter": "example_value"
        })

        _response = _srv.parse_response(response.to_json(), sformat="json")
        # since no state attribute is involved, a key is minted
        _key = rndstr(16)
        _srv.update_service_context(_response, key=_key)
        info = _srv.client_get("service_context").state.get_item(AccessTokenResponse, 'token_response', _key)
        assert '__expires_at' in info
    def test_construct_refresh_token_request(self):
        auth_request = AuthorizationRequest(
            redirect_uri='https://example.com/cli/authz_cb', state='state')
        auth_response = AuthorizationResponse(code='access_code')
        token_response = AccessTokenResponse(refresh_token="refresh_with_me",
                                             access_token="access")
        _state = State(auth_response=auth_response.to_json(),
                       auth_request=auth_request.to_json(),
                       token_response=token_response.to_json())

        self.client.state_db.set('ABCDE', _state.to_json())
        req_args = {}
        msg = self.client.service['refresh_token'].construct(
            request_args=req_args, state='ABCDE')
        assert isinstance(msg, RefreshAccessTokenRequest)
        assert msg.to_dict() == {
            'client_id': 'client_1',
            'client_secret': 'abcdefghijklmnop',
            'grant_type': 'refresh_token',
            'refresh_token': 'refresh_with_me'
        }