Пример #1
0
def test_access_token_srv_conf():
    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_request = AuthorizationRequest(
        redirect_uri='https://example.com/cli/authz_cb', state='state')
    auth_response = AuthorizationResponse(code='access_code')

    _state = State(auth_request=auth_request.to_json(),
                   auth_response=auth_response.to_json())
    db.set('state', _state.to_json())

    service = service_factory(
        'AccessToken', ['oauth2'],
        state_db=db,
        service_context=service_context,
        conf={'default_authn_method': 'client_secret_post'})

    req_args = {
        'redirect_uri': 'https://example.com/cli/authz_cb',
        'code': 'access_code'
    }
    service.endpoint = 'https://example.com/authorize'
    _info = service.get_request_parameters(request_args=req_args,
                                           state='state')

    assert _info
    msg = AccessTokenRequest().from_urlencoded(
        service.get_urlinfo(_info['body']))
    assert 'client_secret' in msg
    def create_request(self):
        self._iss = ISS
        client_config = {
            'client_id': 'client_id', 'client_secret': 'a longesh password',
            'redirect_uris': ['https://example.com/cli/authz_cb'],
            'issuer': self._iss, 'requests_dir': 'requests',
            'base_url': 'https://example.com/cli/'
        }
        service_context = ServiceContext(config=client_config)
        service_context.keyjar = CLI_KEY
        service_context.behaviour = {
            'userinfo_signed_response_alg': 'RS256',
            "userinfo_encrypted_response_alg": "RSA-OAEP",
            "userinfo_encrypted_response_enc": "A256GCM"
        }

        db = InMemoryStateDataBase()
        auth_response = AuthorizationResponse(code='access_code').to_json()

        idtval = {
            'nonce': 'KUEYfRM2VzKDaaKD', 'sub': 'diana',
            'iss': ISS, 'aud': 'client_id'
        }
        idt = create_jws(idtval)

        ver_idt = IdToken().from_jwt(idt, CLI_KEY)

        token_response = AccessTokenResponse(
            access_token='access_token', id_token=idt,
            __verified_id_token=ver_idt).to_json()
        db.set('abcde', State(token_response=token_response,
                              auth_response=auth_response).to_json())
        self.service = service_factory('UserInfo', ['oidc'], state_db=db,
                                       service_context=service_context)
Пример #3
0
def services():
    db = InMemoryStateDataBase()
    auth_request = AuthorizationRequest(redirect_uri="http://example.com",
                                        state='ABCDE').to_json()
    auth_response = AuthorizationResponse(access_token="token",
                                          state='ABCDE').to_json()
    db.set(
        'ABCDE',
        State(iss='Issuer',
              auth_request=auth_request,
              auth_response=auth_response).to_json())
    return init_services(DEFAULT_SERVICES, get_service_context(), db)
 def create_request(self):
     client_config = {
         'client_id': 'client_id', 'client_secret': 'a longesh password',
         'redirect_uris': ['https://example.com/cli/authz_cb']
     }
     service_context = ServiceContext(CLI_KEY, config=client_config)
     _db = InMemoryStateDataBase()
     auth_request = AuthorizationRequest(
         redirect_uri='https://example.com/cli/authz_cb',
         state='state', response_type='code').to_json()
     auth_response = AuthorizationResponse(code='access_code').to_json()
     _db.set('state', State(auth_response=auth_response,
                            auth_request=auth_request).to_json())
     self.service = service_factory('AccessToken', ['oidc'], state_db=_db,
                                    service_context=service_context)
Пример #5
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 create_service(self):
     service_context = ServiceContext(client_id='client_id',
                                      issuer='https://www.example.org/as')
     db = InMemoryStateDataBase()
     db.set('state', State(iss='Issuer').to_json())
     self.service = DummyService(service_context, state_db=db)