private string CreateDeviceCodeRequestUriString() { var deviceCodeRequestParameters = new DictionaryRequestParameters(this.resource, this.clientKey); if (this.callState != null && this.callState.CorrelationId != Guid.Empty) { deviceCodeRequestParameters[OAuthParameter.CorrelationId] = this.callState.CorrelationId.ToString(); } if (PlatformPlugin.HttpClientFactory.AddAdditionalHeaders) { IDictionary <string, string> adalIdParameters = AdalIdHelper.GetAdalIdParameters(); foreach (KeyValuePair <string, string> kvp in adalIdParameters) { deviceCodeRequestParameters[kvp.Key] = kvp.Value; } } if (!string.IsNullOrWhiteSpace(extraQueryParameters)) { // Checks for extraQueryParameters duplicating standard parameters Dictionary <string, string> kvps = EncodingHelper.ParseKeyValueList(extraQueryParameters, '&', false, this.callState); foreach (KeyValuePair <string, string> kvp in kvps) { if (deviceCodeRequestParameters.ContainsKey(kvp.Key)) { throw new AdalException(AdalError.DuplicateQueryParameter, string.Format(CultureInfo.CurrentCulture, AdalErrorMessage.DuplicateQueryParameterTemplate, kvp.Key)); } } deviceCodeRequestParameters.ExtraQueryParameter = extraQueryParameters; } return(new Uri(new Uri(this.authenticator.DeviceCodeUri), "?" + deviceCodeRequestParameters).AbsoluteUri); }
protected virtual async Task <AuthenticationResultEx> SendTokenRequestAsync() { var requestParameters = new DictionaryRequestParameters(this.Resource, this.ClientKey); this.AddAditionalRequestParameters(requestParameters); return(await this.SendHttpMessageAsync(requestParameters)); }
protected override void AddAditionalRequestParameters(DictionaryRequestParameters requestParameters) { requestParameters[OAuthParameter.GrantType] = OAuthGrantType.JwtBearer; requestParameters[OAuthParameter.Assertion] = this.userAssertion.Assertion; requestParameters[OAuthParameter.RequestedTokenUse] = OAuthRequestedTokenUse.OnBehalfOf; // To request id_token in response requestParameters[OAuthParameter.Scope] = OAuthValue.ScopeOpenId; }
internal override void ApplyTo(DictionaryRequestParameters requestParameters) { requestParameters[OAuthParameter.GrantType] = OAuthGrantType.Password; requestParameters[OAuthParameter.Username] = this.UserName; requestParameters[OAuthParameter.Password] = new string(PasswordToCharArray()); if (SecurePassword != null) { SecurePassword.Clear(); } }
private DictionaryRequestParameters CreateAuthorizationRequest(string loginHint) { var authorizationRequestParameters = new DictionaryRequestParameters(this.Resource, this.ClientKey); authorizationRequestParameters[OAuthParameter.ResponseType] = OAuthResponseType.Code; authorizationRequestParameters[OAuthParameter.HasChrome] = "1"; authorizationRequestParameters[OAuthParameter.RedirectUri] = this.redirectUriRequestParameter; if (!string.IsNullOrWhiteSpace(loginHint)) { authorizationRequestParameters[OAuthParameter.LoginHint] = loginHint; } if (this.CallState != null && this.CallState.CorrelationId != Guid.Empty) { authorizationRequestParameters[OAuthParameter.CorrelationId] = this.CallState.CorrelationId.ToString(); } if (this.authorizationParameters != null) { PlatformPlugin.PlatformInformation.AddPromptBehaviorQueryParameter(this.authorizationParameters, authorizationRequestParameters); } if (PlatformPlugin.HttpClientFactory.AddAdditionalHeaders) { IDictionary <string, string> adalIdParameters = AdalIdHelper.GetAdalIdParameters(); foreach (KeyValuePair <string, string> kvp in adalIdParameters) { authorizationRequestParameters[kvp.Key] = kvp.Value; } } if (!string.IsNullOrWhiteSpace(extraQueryParameters)) { // Checks for extraQueryParameters duplicating standard parameters Dictionary <string, string> kvps = EncodingHelper.ParseKeyValueList(extraQueryParameters, '&', false, this.CallState); foreach (KeyValuePair <string, string> kvp in kvps) { if (authorizationRequestParameters.ContainsKey(kvp.Key)) { throw new AdalException(AdalError.DuplicateQueryParameter, string.Format(CultureInfo.CurrentCulture, AdalErrorMessage.DuplicateQueryParameterTemplate, kvp.Key)); } } authorizationRequestParameters.ExtraQueryParameter = extraQueryParameters; } return(authorizationRequestParameters); }
protected override void AddAditionalRequestParameters(DictionaryRequestParameters requestParameters) { if (this.userAssertion != null) { requestParameters[OAuthParameter.GrantType] = this.userAssertion.AssertionType; requestParameters[OAuthParameter.Assertion] = Convert.ToBase64String(Encoding.UTF8.GetBytes(this.userAssertion.Assertion)); } else { this.userCredential.ApplyTo(requestParameters); } // To request id_token in response requestParameters[OAuthParameter.Scope] = OAuthValue.ScopeOpenId; }
protected async Task <AuthenticationResultEx> SendTokenRequestByRefreshTokenAsync(string refreshToken) { var requestParameters = new DictionaryRequestParameters(this.Resource, this.ClientKey); requestParameters[OAuthParameter.GrantType] = OAuthGrantType.RefreshToken; requestParameters[OAuthParameter.RefreshToken] = refreshToken; requestParameters[OAuthParameter.Scope] = OAuthValue.ScopeOpenId; AuthenticationResultEx result = await this.SendHttpMessageAsync(requestParameters); if (result.RefreshToken == null) { result.RefreshToken = refreshToken; PlatformPlugin.Logger.Verbose(this.CallState, "Refresh token was missing from the token refresh response, so the refresh token in the request is returned instead"); } return(result); }
public override void AddPromptBehaviorQueryParameter(IPlatformParameters parameters, DictionaryRequestParameters authorizationRequestParameters) { PlatformParameters authorizationParameters = (parameters as PlatformParameters); if (authorizationParameters == null) { throw new ArgumentException("parameters should be of type PlatformParameters", "parameters"); } PromptBehavior promptBehavior = (parameters as PlatformParameters).PromptBehavior; // ADFS currently ignores the parameter for now. switch (promptBehavior) { case PromptBehavior.Always: authorizationRequestParameters[OAuthParameter.Prompt] = PromptValue.Login; break; case PromptBehavior.RefreshSession: authorizationRequestParameters[OAuthParameter.Prompt] = PromptValue.RefreshSession; break; case PromptBehavior.Never: authorizationRequestParameters[OAuthParameter.Prompt] = PromptValue.AttemptNone; break; } }
protected abstract void AddAditionalRequestParameters(DictionaryRequestParameters requestParameters);
public virtual void AddPromptBehaviorQueryParameter(IPlatformParameters parameters, DictionaryRequestParameters authorizationRequestParameters) { authorizationRequestParameters[OAuthParameter.Prompt] = PromptValue.Login; }
protected override void AddAditionalRequestParameters(DictionaryRequestParameters requestParameters) { }
protected override void AddAditionalRequestParameters(DictionaryRequestParameters requestParameters) { requestParameters[OAuthParameter.GrantType] = OAuthGrantType.AuthorizationCode; requestParameters[OAuthParameter.Code] = this.authorizationCode; requestParameters[OAuthParameter.RedirectUri] = this.redirectUri.OriginalString; }
protected override void AddAditionalRequestParameters(DictionaryRequestParameters requestParameters) { requestParameters[OAuthParameter.GrantType] = OAuthGrantType.DeviceCode; requestParameters[OAuthParameter.Code] = this.deviceCodeResult.DeviceCode; }