How to use the adal.wstrust_request.WSTrustRequest 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 create_wstrust_request_stub(self, err, tokenType, noToken=None):
            wstrust_response = WSTrustResponse(cp['callContext'],'')
            wstrust_response.error_code = err
            wstrust_response.parse = mock.MagicMock()
            if not noToken:
                wstrust_response.token = 'This is a stubbed token'
                wstrust_response._tokenType = tokenType
                wstrust_response.token_type = tokenType

            wstrust_request = WSTrustRequest(cp['callContext'], '', '')

            def side_effect (username, password):
                if err:
                    raise AdalError("Throwing error from Unit test")
                return wstrust_response
            wstrust_request.acquire_token = mock.MagicMock(side_effect=side_effect)

            return wstrust_request
github AzureAD / azure-activedirectory-library-for-python / tests / test_wstrust_request.py View on Github external
    @httpretty.activate
    def test_happy_path(self):
        username = 'test_username'
        password = 'test_password'
        appliesTo = 'test_appliesTo'
        wstrustFile = open(os.path.join(os.getcwd(), 'tests', 'wstrust', 'RST.xml'), mode='r')
        templateRST = wstrustFile.read()
        rst = templateRST \
            .replace('%USERNAME%', username) \
            .replace('%PASSWORD%', password) \
            .replace('%APPLIES_TO%', appliesTo) \
            .replace('%WSTRUST_ENDPOINT%', wstrustEndpoint)

        #rstRequest = setupUpOutgoingRSTCompare(rst)
        request = WSTrustRequest(_call_context, wstrustEndpoint, appliesTo, WSTrustVersion.WSTRUST13)

        # TODO: handle rstr should be mocked out to prevent handling here.
        # TODO: setupUpOutgoingRSTCompare.  Use this to get messageid, created, expires, etc comparisons.

        httpretty.register_uri(method=httpretty.POST, uri=wstrustEndpoint, status=200, body='')

        request._handle_rstr =mock.MagicMock()

        request.acquire_token(username, password)
        wstrustFile.close()
github AzureAD / azure-activedirectory-library-for-python / adal / token_request.py View on Github external
def _create_wstrust_request(self, wstrust_endpoint, applies_to, wstrust_endpoint_version):
        return wstrust_request.WSTrustRequest(self._call_context, wstrust_endpoint,
                                              applies_to, wstrust_endpoint_version)
github AzureAD / azure-activedirectory-library-for-python / adal / wstrust_request.py View on Github external
    @staticmethod
    def _populate_rst_username_password(template, username, password):
        password = WSTrustRequest._escape_password(password)
        return template.replace(_USERNAME_PLACEHOLDER, username).replace(_PASSWORD_PLACEHOLDER, password)
github AzureAD / azure-activedirectory-library-for-python / adal / wstrust_request.py View on Github external
if self._wstrust_endpoint_version == WSTrustVersion.WSTRUST2005:
            soap_action = 'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue'
            rst_trust_namespace = 'http://schemas.xmlsoap.org/ws/2005/02/trust'
            key_type = 'http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey'
            request_type = 'http://schemas.xmlsoap.org/ws/2005/02/trust/Issue'
   
        rst_template = ("".format(schema_location) +
                        "" + 
                        "{}".format(soap_action) +
                        "urn:uuid:{}".format(message_id) +
                        "" +
                        "http://www.w3.org/2005/08/addressing/anonymous" +
                        "" +
                        "{}".format(self._wstrust_endpoint_url) +
                        WSTrustRequest._build_security_header() +
                        "" +
                        "" +
                        "".format(rst_trust_namespace) +
                        "" + 
                        "" +
                        "{}".format(self._applies_to) +
                        "" +
                        "" +
                        "{}".format(key_type) +
                        "{}".format(request_type) +
                        "" +
                        "" +
                        "")

        self._log.debug('Created RST: \n %(rst_template)s',
                        {"rst_template": rst_template})
github AzureAD / azure-activedirectory-library-for-python / adal / wstrust_request.py View on Github external
"" +
                        "".format(rst_trust_namespace) +
                        "" + 
                        "" +
                        "{}".format(self._applies_to) +
                        "" +
                        "" +
                        "{}".format(key_type) +
                        "{}".format(request_type) +
                        "" +
                        "" +
                        "")

        self._log.debug('Created RST: \n %(rst_template)s',
                        {"rst_template": rst_template})
        return WSTrustRequest._populate_rst_username_password(rst_template, username, password)

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