Created
December 23, 2022 20:15
-
-
Save DmitrySikorsky/a6b4dbc978f8b41cbf044fa26ab894cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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