Skip to content

Instantly share code, notes, and snippets.

@DmitrySikorsky
Created December 23, 2022 20:15
Show Gist options
  • Save DmitrySikorsky/a6b4dbc978f8b41cbf044fa26ab894cf to your computer and use it in GitHub Desktop.
Save DmitrySikorsky/a6b4dbc978f8b41cbf044fa26ab894cf to your computer and use it in GitHub Desktop.
private async Task<string> GetEmailFromGoogleCode(string googleCode)
{
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets()
{
ClientId = "XXXXXXXXXX.apps.googleusercontent.com",
ClientSecret = "XXXXXXXXXX"
},
Scopes = new[] { "email" },
}
);
TokenResponse token = await flow.ExchangeCodeForTokenAsync(string.Empty, googleCode, string.Empty, CancellationToken.None);
JwtSecurityToken jwt = new JwtSecurityToken(token.IdToken);
return jwt.Claims.First(c => c.Type == ClaimTypes.Email).Value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment