Say I have the following response from Google\'s OAuth2 /token
endpoint after exchanging the code obtained from the /auth
endpoint (using this example
C# solution, though I'm not sure if it works in all cases:
using System.Linq;
using System.Security.Cryptography;
using System.Text;
static readonly char[] padding = { '=' };
private static string CreateGoogleAtHash(string accessToken)
{
using (SHA256 sha256Hash = SHA256.Create())
{
byte[] bytes = sha256Hash.ComputeHash(Encoding.ASCII.GetBytes(accessToken));
byte[] firstHalf = bytes.Take(bytes.Length / 2).ToArray();
return System.Convert.ToBase64String(firstHalf).TrimEnd(padding).Replace('+', '-').Replace('/', '_');
}
}