How to use the adal.token_request.TokenRequest function in adal

To help you get started, we’ve selected a few adal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AzureAD / azure-activedirectory-library-for-python / tests / test_username_password.py View on Github external
def test_federated_wstrust_unknown_token_type(self):
            context = self.create_authentication_context_stub(cp['authorityTenant'])
            mex = self.create_mex_stub(cp['adfsWsTrust'])
            userRealm = self.create_user_realm_stub('wstrust', 'federated', None, cp['adfsWsTrust'])
            wstrustRequest = self.create_wstrust_request_stub(None, 'urn:oasis:names:tc:SAML:100.0:assertion', True)

            response = util.create_response()
            oauthClient = self.create_oauth2_client_stub(cp['authority'], response['decodedResponse'], None)

            #util.turnOnLogging()
            tokenRequest = TokenRequest(cp['callContext'], context, response['clientId'], response['resource'])
            self.stub_out_token_request_dependencies(tokenRequest, userRealm, mex, wstrustRequest, oauthClient)

            try:
                tokenRequest.get_token_with_username_password(user_pass_params['username'], user_pass_params['password'])
            except Exception as exp:
                receivedException = True
                pass
            finally:
                self.assertTrue(receivedException, 'Did not receive expected error')
github AzureAD / azure-activedirectory-library-for-python / tests / test_username_password.py View on Github external
def test_federated_user_realm_returns_no_mex_endpoint(self):
            context = self.create_authentication_context_stub(cp['authority'])
            mex = self.create_mex_stub(cp['adfsWsTrust'])
            userRealm = self.create_user_realm_stub('wstrust', 'federated', None, cp['adfsWsTrust'])
            wstrustRequest = self.create_wstrust_request_stub(None, 'urn:oasis:names:tc:SAML:1.0:assertion')

            response = util.create_response()
            oauthClient = self.create_oauth2_client_stub(cp['authority'], response['decodedResponse'], None)

            #util.turnOnLogging()
            tokenRequest = TokenRequest(cp['callContext'], context, response['clientId'], response['resource'])
            self.stub_out_token_request_dependencies(tokenRequest, userRealm, mex, wstrustRequest, oauthClient)

            receivedException = False
            try:
                token_response = tokenRequest.get_token_with_username_password(user_pass_params['username'], user_pass_params['password'])
            except Exception as exp:
                receivedException = True
                pass
            finally:
                if not receivedException:
                    self.assertTrue(util.is_match_token_response(response['cachedResponse'], token_response), 'The response did not match what was expected')
github AzureAD / azure-activedirectory-library-for-python / tests / test_username_password.py View on Github external
def test_federated_failed_mex(self):
            context = self.create_authentication_context_stub(cp['authorityTenant'])
            mex = self.create_mex_stub(cp['adfsWsTrust'], Exception('mex failed'))
            userRealm = self.create_user_realm_stub('wstrust', 'federated', cp['adfsMex'], cp['adfsWsTrust'])
            wstrustRequest = self.create_wstrust_request_stub(None, 'urn:oasis:names:tc:SAML:1.0:assertion')

            response = util.create_response()
            oauthClient = self.create_oauth2_client_stub(cp['authority'], response['cachedResponse'], None)

            tokenRequest = TokenRequest(cp['callContext'], context, response['clientId'], response['resource'])
            self.stub_out_token_request_dependencies(tokenRequest, userRealm, mex, wstrustRequest, oauthClient)

            receivedException = True
            try:
                token_response = tokenRequest.get_token_with_username_password(user_pass_params['username'], user_pass_params['password'])
            except Exception as exp:
                receivedException = True
                pass
            finally:
                if not receivedException:
                    self.assertTrue(util.is_match_token_response(response['cachedResponse'], token_response), 'The response did not match what was expected')
github AzureAD / azure-activedirectory-library-for-python / tests / test_username_password.py View on Github external
        @unittest.skip('https://github.com/AzureAD/azure-activedirectory-library-for-python-priv/issues/21')
        def test_federated_unknown_token_type(self):
            ''' TODO: Test Failing as of 2015/06/03 and needs to be completed. '''
            context = self.create_authentication_context_stub(cp['authorityTenant'])
            mex = self.create_mex_stub(cp['adfsWsTrust'])
            userRealm = self.create_user_realm_stub('wstrust', 'federated', cp['adfsMex'], cp['adfsWsTrust'])
            wstrustRequest = self.create_wstrust_request_stub(None, 'urn:oasis:names:tc:SAML:100.0:assertion')

            response = util.create_response()
            oauthClient = self.create_oauth2_client_stub(cp['authority'], response['decodedResponse'], None)

            #util.turnOnLogging()
            tokenRequest = TokenRequest(cp['callContext'], context, response['clientId'], response['resource'])
            self.stub_out_token_request_dependencies(tokenRequest, userRealm, mex, wstrustRequest, oauthClient)

            try:
                tokenRequest.get_token_with_username_password(user_pass_params['username'], user_pass_params['password'])
            except Exception as err:
                receivedException = True
                self.assertTrue('tokenType' in  err.args[0], "Error message did not contain 'token type'. message:{}".format(err.args[0]))
                pass
            finally:
                self.assertTrue(receivedException, 'Did not receive expected error')
github AzureAD / azure-activedirectory-library-for-python / adal / authentication_context.py View on Github external
def token_func(self):
            token_request = TokenRequest(self._call_context, self, client_id, resource)
            return token_request.get_token_with_refresh_token(refresh_token, client_secret)
github AzureAD / azure-activedirectory-library-for-python / adal / authentication_context.py View on Github external
def token_func(self):
            token_request = TokenRequest(self._call_context, self, client_id, resource)
            return token_request.get_token_from_cache_with_refresh(user_id)
github AzureAD / azure-activedirectory-library-for-python / adal / token_request.py View on Github external
def _get_token_username_password_federated(self, username, password):
        self._log.debug("Acquiring token with username password for federated user")

        if not self._user_realm.federation_metadata_url:
            self._log.warn("Unable to retrieve federationMetadataUrl from AAD. "
                           "Attempting fallback to AAD supplied endpoint.")

            if not self._user_realm.federation_active_auth_url:
                raise AdalError('AAD did not return a WSTrust endpoint. Unable to proceed.')

            wstrust_version = TokenRequest._parse_wstrust_version_from_federation_active_authurl(
                self._user_realm.federation_active_auth_url)
            self._log.debug(
                'wstrust endpoint version is: %(wstrust_version)s',
                {"wstrust_version": wstrust_version})

            return self._perform_username_password_for_access_token_exchange(
                self._user_realm.federation_active_auth_url,
                wstrust_version, username, password)
        else:
            mex_endpoint = self._user_realm.federation_metadata_url
            self._log.debug(
                "Attempting mex at: %(mex_endpoint)s",
                {"mex_endpoint": mex_endpoint})
            mex_instance = self._create_mex(mex_endpoint)
            wstrust_version = WSTrustVersion.UNDEFINED
github AzureAD / azure-activedirectory-library-for-python / adal / authentication_context.py View on Github external
def token_func(self):
            token_request = TokenRequest(self._call_context, self, client_id, resource)
            return token_request.get_token_with_certificate(certificate, thumbprint, public_certificate)
github AzureAD / azure-activedirectory-library-for-python / adal / authentication_context.py View on Github external
def token_func(self):
            token_request = TokenRequest(self._call_context, self, client_id, resource)

            key = user_code_info[OAuth2DeviceCodeResponseParameters.DEVICE_CODE]
            with self._lock:
                self._token_requests_with_user_code[key] = token_request

            token = token_request.get_token_with_device_code(user_code_info)
            
            with self._lock:
                self._token_requests_with_user_code.pop(key, None)
            
            return token
github AzureAD / azure-activedirectory-library-for-python / adal / authentication_context.py View on Github external
def token_func(self):
            token_request = TokenRequest(self._call_context, self, client_id, resource)
            return token_request.get_token_with_client_credentials(client_secret)

adal

Note: This library is already replaced by MSAL Python, available here: https://pypi.org/project/msal/ .ADAL Python remains available here as a legacy. The ADAL for Python library makes it easy for python application to authenticate to Azure Active Directory (AAD) in order to access AAD protected web resources.

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis

Similar packages