def test_parse_authentication_response(self):
     facade = PyoidcFacade(ProviderConfiguration(provider_metadata=self.PROVIDER_METADATA,
                                                 client_metadata=self.CLIENT_METADATA),
                           self.REDIRECT_URI)
     auth_code = 'auth_code-1234'
     state = 'state-1234'
     auth_response = AuthorizationResponse(**{'state': state, 'code': auth_code})
     parsed_auth_response = facade.parse_authentication_response(auth_response.to_dict())
     assert isinstance(parsed_auth_response, AuthorizationResponse)
     assert parsed_auth_response.to_dict() == auth_response.to_dict()
    def test_handle_authentication_response_POST(self):
        access_token = 'test_access_token'
        state = 'test_state'

        authn = self.init_app()
        auth_response = AuthorizationResponse(**{
            'state': state,
            'token_type': 'Bearer',
            'access_token': access_token
        })

        with self.app.test_request_context(
                '/redirect_uri',
                method='POST',
                data=auth_response.to_dict(),
                mimetype='application/x-www-form-urlencoded'):
            UserSession(flask.session, self.PROVIDER_NAME)
            flask.session['destination'] = '/test'
            flask.session['auth_request'] = json.dumps({
                'state': state,
                'nonce': 'test_nonce'
            })
            response = authn._handle_authentication_response()
            session = UserSession(flask.session)
            assert session.access_token == access_token
            assert response == '/test'