I am trying to read the actual JSON response from Google API after successful OAuth authentication flow. I have read the MS Docs (https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/additional-claims?view=aspnetcore-5.0#establish-the-authentication-scope) where they use options.ClaimActions.MapJsonKey to map each key to a Claim. However I do not want to add claims, I just want to read all of the JSON keys and values returned.
.AddGoogle(options => {
options.ClientId = _conf["MyClientId"];
options.ClientSecret = _conf["MySecret"];
options.Events.OnCreatingTicket = ctx => {
// How do I read the JSON returned, via ctx object? I have tried ctx.Response.Body, but didn't get much further.
return Task.CompletedTask;
};
Instead of checking the Context.Response for the JSON payload, one has to access the Context.TokenResponse, the "response from an provider for an OAuth token request":
Source: https://learn.microsoft.com/en-nz/dotnet/api/microsoft.aspnetcore.authentication.oauth.oauthtokenresponse?view=aspnetcore-2.0.