asp.net mvc API get facebook token

前端 未结 1 946
小鲜肉
小鲜肉 2020-12-20 06:57

I\'ve created an application with asp.net mvc api with users, following this tutorial. And everything works great like that. local users and facebook login works fine.

相关标签:
1条回答
  • 2020-12-20 07:24
    var options = new FacebookAuthenticationOptions
    {
        AppId = "Your App ID",
        AppSecret = "Your App Secret",
        Provider = new FacebookAuthenticationProvider
        {
            OnAuthenticated = async context =>
            {
                // Retrieve the OAuth access token to store for subsequent API calls
                string accessToken = context.AccessToken;
    
                // Retrieve the username
                string facebookUserName = context.UserName;
    
                // You can even retrieve the full JSON-serialized user
                var serializedUser = context.User;
            }
        }
    };
    
    app.UseFacebookAuthentication(options);
    

    For more info on how to do this stuff see here: http://www.oauthforaspnet.com/providers/facebook/ f the OnAuthenticated you could also add:

    context.Identity.AddClaim(new Claim("FacebookToken", accessToken));
    

    As I am pretty sure that at this point we have created the user and created their claims so you

    0 讨论(0)
提交回复
热议问题