| 1 | using System.Security.Cryptography; |
| 2 | using System.Text; |
| 3 | |
| 4 | namespace IntercomService.Services; |
| 5 | |
| 6 | internal static class OAuthPkce |
| 7 | { |
| 8 | public static bool ValidateS256(string? codeVerifier, string? codeChallenge) |
| 9 | { |
| 10 | if (string.IsNullOrWhiteSpace(codeVerifier) || string.IsNullOrWhiteSpace(codeChallenge)) |
| 11 | return false; |
| 12 | |
| 13 | var hash = SHA256.HashData(Encoding.ASCII.GetBytes(codeVerifier)); |
| 14 | var computed = Base64UrlEncode(hash); |
| 15 | return string.Equals(computed, codeChallenge.Trim(), StringComparison.Ordinal); |
| 16 | } |
| 17 | |
| 18 | private static string Base64UrlEncode(byte[] bytes) => |
| 19 | Convert.ToBase64String(bytes).TrimEnd('=').Replace('+', '-').Replace('/', '_'); |
| 20 | } |
| 21 | |
View only · write via MCP/CIDE