Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Buffers.Text;
using System.Security.Cryptography;
using System.Text;
using GitCredentialManager.Authentication.OAuth;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void OAuth2CryptographicCodeGenerator_CreatePkceCodeChallenge_Sha256_Retu
hashedBytes = sha256.ComputeHash(verifierAsciiBytes);
}

var expectedChallenge = Base64UrlConvert.Encode(hashedBytes, false);
var expectedChallenge = Base64Url.EncodeToString(hashedBytes);
var actualChallenge = generator.CreatePkceCodeChallenge(OAuth2PkceChallengeMethod.Sha256, verifier);

Assert.Equal(expectedChallenge, actualChallenge);
Expand Down
35 changes: 0 additions & 35 deletions src/Core.Tests/Base64UrlConvertTests.cs

This file was deleted.

11 changes: 4 additions & 7 deletions src/Core/Authentication/OAuth/OAuth2CryptographicGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Buffers.Text;
using System.Security.Cryptography;
using System.Text;

Expand Down Expand Up @@ -35,9 +36,6 @@ public interface IOAuth2CodeGenerator

public class OAuth2CryptographicCodeGenerator : IOAuth2CodeGenerator
{
// Do not include padding of the base64url string to avoid percent-encoding when passed in a URI
private const bool PkceIncludeBase64UrlPadding = false;

public string CreateNonce()
{
return Guid.NewGuid().ToString("N");
Expand Down Expand Up @@ -72,7 +70,7 @@ public string CreatePkceCodeVerifier()
var rng = RandomNumberGenerator.Create();
rng.GetBytes(buf);

return Base64UrlConvert.Encode(buf, PkceIncludeBase64UrlPadding);
return Base64Url.EncodeToString(buf);
}

public string CreatePkceCodeChallenge(OAuth2PkceChallengeMethod challengeMethod, string codeVerifier)
Expand All @@ -89,11 +87,10 @@ public string CreatePkceCodeChallenge(OAuth2PkceChallengeMethod challengeMethod,
//
using (var sha256 = SHA256.Create())
{
return Base64UrlConvert.Encode(
return Base64Url.EncodeToString(
sha256.ComputeHash(
Encoding.ASCII.GetBytes(codeVerifier)
),
PkceIncludeBase64UrlPadding
)
);
}

Expand Down
25 changes: 0 additions & 25 deletions src/Core/Base64UrlConvert.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/TestInfrastructure/Objects/TestOAuth2Server.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Buffers.Text;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -421,11 +422,10 @@ public TokenEndpointResponseJson CreateTokenByAuthorizationGrant(
case OAuth2PkceChallengeMethod.Sha256:
using (var sha256 = SHA256.Create())
{
string challenge = Base64UrlConvert.Encode(
string challenge = Base64Url.EncodeToString(
sha256.ComputeHash(
Encoding.ASCII.GetBytes(codeVerifier)
),
false
)
);

if (challenge != grant.CodeChallenge)
Expand Down
Loading