4
私はOWINの初心者です。現在、私はVisual Studio 2015を使用してASP.NET MVCプロジェクトを作成しています。ビジュアルスタジオウィザードは、新規ユーザーの登録、外部アカウントのログインなどの基本機能をほとんど処理します。 Startup.Auth.csでは、私はいくつかのユーザーの情報を取得するためにアクセストークンを取得したいが、私は常に、クレームオブジェクトのnull参照の例外を受け取るAccountController.csでOWINを使用してASP.NET MVC 5アプリでFacebookのアクセストークンを保存して取得します
var option = new FacebookAuthenticationOptions
{
AppId = appId,
AppSecret = appSecret,
Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = (ctx) =>
{
ctx.Identity.AddClaim(new System.Security.Claims.Claim("fb_access_token", ctx.AccessToken, ClaimValueTypes.String, "Facebook"));
return Task.FromResult(0);
}
},
AuthenticationType = DefaultAuthenticationTypes.ExternalCookie
};
app.UseFacebookAuthentication(option);
を::
public ActionResult Test()
{
ClaimsIdentity claimIdenties = HttpContext.User.Identity as ClaimsIdentity;
var claim = claimIdenties.FindFirst("fb_access_token");
return View(claim.Value);
}
ことができますあなたたちは次のように機能私に何か解決策を教えてください?私は今、あなたのアカウントコントローラにlater..so
var claimsIdentity = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
if (claimsIdentity != null)
{
// Retrieve the existing claims for the user and add the FacebookAccessTokenClaim
var currentClaims = await UserManager.GetClaimsAsync(user.Id);
var facebookAccessToken = claimsIdentity.FindAll("FacebookAccessToken").First();
if (currentClaims.Count() <= 0)
{
await UserManager.AddClaimAsync(user.Id, facebookAccessToken);
}
それらを取得するために私達のデータベースでfacebook..letsストアアクセストークンを使用してサインアップ時に、あなたの英語