Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }