public void TestConstructorV2() { var samlTokenInfo = new SamlTokenInfo(SamlAssertionType.SamlV2, "an_assertion"); Assert.AreEqual(SamlAssertionType.SamlV2, samlTokenInfo.AssertionType); Assert.AreEqual("an_assertion", samlTokenInfo.Assertion); }
public void TestConstructorV1() { var samlTokenInfo = new SamlTokenInfo(SamlAssertionType.SamlV1, "the_assertion"); Assert.AreEqual(SamlAssertionType.SamlV1, samlTokenInfo.AssertionType); Assert.AreEqual("the_assertion", samlTokenInfo.Assertion); }
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)); }
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)); }