internal void SetupActAsOnBehalfOfParameters(System.IdentityModel.Protocols.WSTrust.FederatedClientCredentialsParameters actAsOnBehalfOfParameters) { if (actAsOnBehalfOfParameters == null) { return; } if (actAsOnBehalfOfParameters.IssuedSecurityToken != null) { throw System.IdentityModel.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.AuthFailed)); } if (actAsOnBehalfOfParameters.OnBehalfOf != null) { if (MessageSecurityVersion.TrustVersion == TrustVersion.WSTrust13) { if (TokenRequestParameterExists(WSTrust13Constants.ElementNames.OnBehalfOf, WSTrust13Constants.NamespaceURI)) { throw System.IdentityModel.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.DuplicateFederatedClientCredentialsParameters, WSTrust13Constants.ElementNames.OnBehalfOf)); } TokenRequestParameters.Add(CreateXmlTokenElement(actAsOnBehalfOfParameters.OnBehalfOf, WSTrust13Constants.Prefix, WSTrust13Constants.ElementNames.OnBehalfOf, WSTrust13Constants.NamespaceURI, SecurityTokenHandlerCollectionManager.Usage.OnBehalfOf)); } else if (MessageSecurityVersion.TrustVersion == TrustVersion.WSTrustFeb2005) { if (TokenRequestParameterExists(WSTrustFeb2005Constants.ElementNames.OnBehalfOf, WSTrustFeb2005Constants.NamespaceURI)) { throw System.IdentityModel.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.DuplicateFederatedClientCredentialsParameters, WSTrustFeb2005Constants.ElementNames.OnBehalfOf)); } TokenRequestParameters.Add(CreateXmlTokenElement(actAsOnBehalfOfParameters.OnBehalfOf, WSTrustFeb2005Constants.Prefix, WSTrustFeb2005Constants.ElementNames.OnBehalfOf, WSTrustFeb2005Constants.NamespaceURI, SecurityTokenHandlerCollectionManager.Usage.OnBehalfOf)); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.UnsupportedTrustVersion, MessageSecurityVersion.TrustVersion.Namespace))); } } if (actAsOnBehalfOfParameters.ActAs != null) { if (TokenRequestParameterExists(WSTrust14Constants.ElementNames.ActAs, WSTrust14Constants.NamespaceURI)) { throw System.IdentityModel.DiagnosticUtility.ThrowHelperInvalidOperation(SR.GetString(SR.DuplicateFederatedClientCredentialsParameters, WSTrust14Constants.ElementNames.ActAs)); } TokenRequestParameters.Add(CreateXmlTokenElement(actAsOnBehalfOfParameters.ActAs, WSTrust14Constants.Prefix, WSTrust14Constants.ElementNames.ActAs, WSTrust14Constants.NamespaceURI, SecurityTokenHandlerCollectionManager.Usage.ActAs)); } }
/// <summary> /// Creates the form content to request a refresh of an authentication token /// </summary> private static string GetRefreshTokenFormContent() { StringBuilder contentBuilder = new StringBuilder(); TokenRequestParameters parameters = new TokenRequestParameters(); contentBuilder.AppendLine(); contentBuilder.Append(SetFormContentDisposition("grant_type", "refresh_token")); contentBuilder.Append(SetFormContentDisposition("client_id", parameters.client_id)); contentBuilder.Append(SetFormContentDisposition("client_secret", parameters.client_secret)); contentBuilder.Append(SetFormContentDisposition("refresh_token", Settings.Token.refresh_token)); contentBuilder.Append(FinalizeFormDisposition()); return(contentBuilder.ToString()); }
/// <summary> /// Creates the form content to request a token refresh /// </summary> /// <returns></returns> private static string GetRefreshTokenFormContent() { StringBuilder contentBuilder = new StringBuilder(); TokenRequestParameters parameters = new TokenRequestParameters(); contentBuilder.AppendLine(); try { contentBuilder.Append(SetFormContentDisposition("grant_type", "refresh_token")); contentBuilder.Append(SetFormContentDisposition("client_id", parameters.client_id)); contentBuilder.Append(SetFormContentDisposition("client_secret", parameters.client_secret)); contentBuilder.Append(SetFormContentDisposition("refresh_token", Settings.Token.refresh_token)); contentBuilder.Append(FinalizeFormDisposition()); } catch (Exception ex) { CrestronConsole.PrintLine("SimplTeslaMaster.WebRequests.ContentFactory.GetRefreshTokenFormContent()::Failed to get form content " + ex.ToString()); } return(contentBuilder.ToString()); }
public async Task <TokenResponse> ValidateURLClientIdClientSecret(string baseurl, TokenRequestParameters requestParameters) { TokenResponse result = new TokenResponse(); if (!string.IsNullOrEmpty(baseurl)) { var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Applications/ValidateURLClientIdClientSecret")); try { var jsonResult = await GetTokenAsync <TokenRequestParameters>(requestUrl, requestParameters); TokenParameters response = JsonConvert.DeserializeObject <TokenParameters>(jsonResult); if (response != null && response.Token != null) { result.data = response.Token; result.message = "Token Generated"; } else if (jsonResult.Contains("passed is incorrect.")) { result.message = "ClientId or ClientSecret is incorrect"; } else if (jsonResult.Contains("does not exist.")) { result.message = "Website Url does not exists in the system"; } } catch { } } return(result); }