Is it possible to add claims to a Bearer Token in order to access those claims in the future? This is the Bearer Token that is issued by the Web API. It is contained in the URL that is displayed upon redirect from the Twitter app authorization process.
The reason I ask is that I'm trying to store the Twitter AccessToken and AccessTokenSecret as additional claims. I'm doing this so that I can access these claims when I access the GetUserInfo method using a Bearer Token. From what I can tell, this is not possible.
It seems like I might have to store these in SQL and retrieve them using the Twitter userName when I access GetUserInfo. When I access GetUserInfo, I get the Twitter userName and userId, but I can't get the AccessToken and AccessTokenSecret. I might be able to store the context.ScreenName, context.AccessToken and context.AccessTokenSecret in SQL using the public override Task Authenticated(TwitterAuthenticatedContext context) method.
I need the AccessToken and AccessTokenSecret, so I can call this Twitter endpoint to get the user's email address.
https://api.twitter.com/1.1/account/verify_credentials.json
At this stage in the process, my user is not logged in and their local account has not been created. I am attempting to get the email address from Twitter in order to create their local account.
UPDATE 1
Here is some code. I'm calling this method from Provider in TwitterAuthenticationOptions in Startup.Auth like so. As you can see, I'm adding the claims to the context in Authenticated.
Provider = new TwitterAuthProvider(),
public class TwitterAuthProvider : TwitterAuthenticationProvider
{
public string XmlSchemaString { get; private set; }
public override Task Authenticated(TwitterAuthenticatedContext context)
{
context.Identity.AddClaim(new Claim("access_token", context.AccessToken, XmlSchemaString, "Twitter"));
context.Identity.AddClaim(new Claim("access_token_secret", context.AccessTokenSecret, XmlSchemaString, "Twitter"));
context.Identity.AddClaim(new Claim("user_name", context.ScreenName, XmlSchemaString, "Twitter"));
context.Identity.AddClaim(new Claim("account_type", "Twitter", XmlSchemaString, "Twitter"));
return Task.FromResult<object>(null);
}
}
Any help is much appreciated. Thanks in advance!