Skip to content

Commit 8d4c0c4

Browse files
committed
Make sure we're consistent
1 parent 7c33562 commit 8d4c0c4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/ModelContextProtocol/Auth/OAuthService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,12 @@ private string GenerateRandomString(int length)
363363
var bytes = new byte[length];
364364
using var rng = RandomNumberGenerator.Create();
365365
rng.GetBytes(bytes);
366-
return Convert.ToBase64String(bytes)
367-
.Replace('+', '-')
368-
.Replace('/', '_')
369-
.Replace("=", "")
370-
.Substring(0, length);
366+
367+
// Use the optimized Base64UrlHelpers for encoding
368+
string base64Url = Base64UrlHelpers.Encode(bytes);
369+
370+
// Ensure we return exactly the requested length
371+
return base64Url.Substring(0, Math.Min(base64Url.Length, length));
371372
}
372373

373374
// This method would be used in a real implementation after receiving the authorization code

0 commit comments

Comments
 (0)