예제 #1
0
        public void TestConstructorV2()
        {
            var samlTokenInfo = new SamlTokenInfo(SamlAssertionType.SamlV2, "an_assertion");

            Assert.AreEqual(SamlAssertionType.SamlV2, samlTokenInfo.AssertionType);
            Assert.AreEqual("an_assertion", samlTokenInfo.Assertion);
        }
예제 #2
0
        public void TestConstructorV1()
        {
            var samlTokenInfo = new SamlTokenInfo(SamlAssertionType.SamlV1, "the_assertion");

            Assert.AreEqual(SamlAssertionType.SamlV1, samlTokenInfo.AssertionType);
            Assert.AreEqual("the_assertion", samlTokenInfo.Assertion);
        }
예제 #3
0
        public async Task <TokenResponse> GetAccessTokenFromSamlGrantAsync(
            SamlTokenInfo samlGrant,
            CancellationToken cancellationToken)
        {
            QueryParameterBuilder queryParams;

            switch (samlGrant.AssertionType)
            {
            case SamlAssertionType.SamlV1:
                queryParams = new QueryParameterBuilder(
                    "grant_type",
                    "urn:ietf:params:oauth:grant-type:saml1_1-bearer");
                break;

            case SamlAssertionType.SamlV2:
                queryParams = new QueryParameterBuilder("grant_type", "urn:ietf:params:oauth:grant-type:saml2-bearer");
                break;

            default:
                throw new InvalidOperationException(); // (MsalXmlException, MSAL_SAML_ENUM_UNKNOWN_VERSION);
            }

            queryParams.AddQueryPair("assertion", EncodingUtils.Base64RfcEncodePadded(samlGrant.Assertion));
            AddClientIdQueryParam(queryParams);
            AddScopeQueryParam(queryParams);
            AddClientInfoQueryParam(queryParams);

            IDictionary <string, string> headers = GetVersionHeaders();

            headers["ContentType"] = "application/x-www-form-urlencoded";

            return(await GetAccessTokenAsync(queryParams, cancellationToken));
        }
예제 #4
0
        public async Task <TokenResponse> GetAccessTokenFromSamlGrantAsync(
            SamlTokenInfo samlGrant,
            CancellationToken cancellationToken)
        {
            QueryParameterBuilder queryParams;

            switch (samlGrant.AssertionType)
            {
            case SamlAssertionType.SamlV1:
                queryParams = new QueryParameterBuilder(
                    "grant_type",
                    "urn:ietf:params:oauth:grant-type:saml1_1-bearer");
                break;

            case SamlAssertionType.SamlV2:
                queryParams = new QueryParameterBuilder("grant_type", "urn:ietf:params:oauth:grant-type:saml2-bearer");
                break;

            default:
                throw new InvalidOperationException(); // (MsalXmlException, MSAL_SAML_ENUM_UNKNOWN_VERSION);
            }

            queryParams.AddQueryPair("assertion", _authenticationParameters.UserName);
            queryParams.AddQueryPair("password", EncodingUtils.Base64RfcEncodePadded(samlGrant.Assertion));
            AddClientIdQueryParam(queryParams);
            AddScopeQueryParam(queryParams);
            AddClientInfoQueryParam(queryParams);

            IDictionary <string, string> headers = GetVersionHeaders();

            headers["Content-Type"] = "application/x-www-form-urlencoded";

            var response = await _httpManager.PostAsync(
                _authenticationParameters.AuthorityUri.GetTokenEndpoint(),
                headers,
                queryParams.ToString(),
                cancellationToken).ConfigureAwait(false);

            return(TokenResponse.Create(response.ResponseData));
        }