public string GenerateCodeVerifier() { byte[] buffer = new byte[Constants.CodeVerifierByteSize]; var windowsBuffer = CryptographicBuffer.GenerateRandom((uint)buffer.Length); Array.Copy(windowsBuffer.ToArray(), buffer, buffer.Length); return(MsalHelpers.EncodeToBase64Url(buffer)); }
public string GenerateCodeVerifier() { byte[] buffer = new byte[Internal.Constants.CodeVerifierByteSize]; using (RNGCryptoServiceProvider randomSource = new RNGCryptoServiceProvider()) { randomSource.GetBytes(buffer); } return(MsalHelpers.EncodeToBase64Url(buffer)); }
private Uri CreateAuthorizationUri(bool addVerifier = false, bool addState = false) { IDictionary <string, string> requestParameters = this.CreateAuthorizationRequestParameters(); if (addVerifier) { _codeVerifier = PlatformPlugin.CryptographyHelper.GenerateCodeVerifier(); string codeVerifierHash = PlatformPlugin.CryptographyHelper.CreateSha256Hash(_codeVerifier); requestParameters[OAuth2Parameter.CodeChallenge] = MsalHelpers.EncodeToBase64Url(codeVerifierHash); requestParameters[OAuth2Parameter.CodeChallengeMethod] = OAuth2Value.CodeChallengeMethodValue; } if (addState) { _state = Guid.NewGuid().ToString(); requestParameters[OAuth2Parameter.State] = _state; } if (!string.IsNullOrWhiteSpace(AuthenticationRequestParameters.ExtraQueryParameters)) { // Checks for _extraQueryParameters duplicating standard parameters Dictionary <string, string> kvps = MsalHelpers.ParseKeyValueList(AuthenticationRequestParameters.ExtraQueryParameters, '&', false, this.CallState); foreach (KeyValuePair <string, string> kvp in kvps) { if (requestParameters.ContainsKey(kvp.Key)) { throw new MsalException(MsalError.DuplicateQueryParameter, string.Format(CultureInfo.InvariantCulture, MsalErrorMessage.DuplicateQueryParameterTemplate, kvp.Key)); } } } string qp = requestParameters.ToQueryParameter(); if (!string.IsNullOrEmpty(AuthenticationRequestParameters.ExtraQueryParameters)) { qp += "&" + AuthenticationRequestParameters.ExtraQueryParameters; } return(new Uri(new Uri(this.Authority.AuthorizationEndpoint), "?" + qp)); }