I am trying to receive more information about the user after successful authentication with facebook in the
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
method of the Account controller.
How am I able to receive the facebook access_token, so that I can use the graph api? I think I may miss something obvious but unfortunately cannot find what I am missing..
Thank you very much for your help!
2
Answers
Set
SaveTokens
to true in options.And get it:
Keep in mind to use
GetTokenAsync
you need to addusing Microsoft.AspNetCore.Authentication;
Access Token may be stored in auth properties (
OAuthOptions.SaveTokens
option enable/disable this behavior,false
by default).Use AuthenticationTokenExtensions class to get token from
AuthenticationProperties
:For example, if you use cookie authentication:
Notice, that before RC2 tokens were stored in claims (related PR), so you may find old code like next one, that doesn’t work