public void QueryParamBuilderTest(string baseUrl) { //Arrange var queryParam = new QueryParameterBuilder(baseUrl) .AddParameter("page", "1") .AddParameter("size", "25"); //Act var url = queryParam.ToString(); //Assert Assert.AreEqual($"{baseUrl}?page=1&size=25", url); }
public async Task <TokenResponse> GetAccessTokenFromUsernamePasswordAsync(CancellationToken cancellationToken) { var queryParams = new QueryParameterBuilder("grant_type", "password"); queryParams.AddQueryPair("username", _authenticationParameters.UserName); queryParams.AddQueryPair("password", _authenticationParameters.Password); AddClientIdQueryParam(queryParams); AddScopeQueryParam(queryParams); AddClientInfoQueryParam(queryParams); var response = await _httpManager.PostAsync( _authenticationParameters.AuthorityUri.GetTokenEndpoint(), GetVersionHeaders(), queryParams.ToString(), cancellationToken).ConfigureAwait(false); return(TokenResponse.Create(response.ResponseData)); }
public async Task <TokenResponse> GetAccessTokenFromAuthCodeAsync( string authCode, CancellationToken cancellationToken) { var queryParams = new QueryParameterBuilder("grant_type", "authorization_code"); queryParams.AddQueryPair("code", authCode); AddRedirectUriQueryParam(queryParams); AddClientIdQueryParam(queryParams); AddScopeQueryParam(queryParams); AddClientInfoQueryParam(queryParams); var response = await _httpManager.PostAsync( _authenticationParameters.AuthorityUri.GetTokenEndpoint(), GetVersionHeaders(), queryParams.ToString(), cancellationToken).ConfigureAwait(false); return(TokenResponse.Create(response.ResponseData)); }
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)); }