あなたは身分証明書を使用しています。しかし、あなたの質問は、facebookアカウントからどのようにクレームを取得するかであり、それらを保持する方法ではありません。だから私は助けてくれるといい。私はCookieのミドルウェアでやっています。 ClaimsPrincipalをFacebookにログインさせるために 'temp' Cookieミドルウェアを追加し、次に、本当のCookieミドルウェアにサインインして、豊富なClaimsPrincipalを維持しました。起動クラスの設定メソッドのコードの関連作品:facebookOptionsのSignInSchemeは「温度」で、「TEMP」クッキーミドルウェアのオプションを使用するので、それはfalseにAutomaticAuthenticate(だ持っているか
app.UseCookieAuthentication(
new CookieAuthenticationOptions()
{
AuthenticationScheme = "Cookie",
AutomaticAuthenticate = true,
AutomaticChallenge = true,
LoginPath = new PathString(@"/account/login"),
AccessDeniedPath = new PathString(@"/account/accessdenied")
});
app.UseCookieAuthentication(
new CookieAuthenticationOptions()
{
AuthenticationScheme = "Temp",
AutomaticAuthenticate = false
});
var facebookOptions = new FacebookOptions()
{
AuthenticationScheme = "Facebook",
SignInScheme = "Temp",
AppId = "yourappidhere",
AppSecret = "yourappsecrethere"
};
facebookOptions.Scope.Add("public_profile");
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
は注意cookiePrincipleをtempクッキーに自動的に永続させたくないが、ここでは「クッキー」と呼ばれる実際のものすべてを豊かにしたい)。 LoginFacebookがあなたのページか何かのリンクを介して呼び出されたか
public async Task<IActionResult> Register(string returnUrl = null)
{
var externalPrincipal = await HttpContext.Authentication.AuthenticateAsync("Temp");
//TODO Check external principal and retrieve claims from db or whatever needs to be done here.
var claims = new List<Claim>()
{
new Claim("email", externalPrincipal.FindFirst(ClaimTypes.Email).Value)
};
var id = new ClaimsIdentity(claims, "password");
await HttpContext.Authentication.SignInAsync("Cookie", new ClaimsPrincipal(id));
await HttpContext.Authentication.SignOutAsync("Temp");
return Redirect(returnUrl);
}
public async Task<IActionResult> LogInFacebook(string returnUrl = null)
{
var queryString = !string.IsNullOrWhiteSpace(returnUrl) ? $"?returnUrl={returnUrl}" : string.Empty;
var props = new AuthenticationProperties() { RedirectUri = [email protected]"Account/Register{queryString}" }; //new PathString(returnUrl)
return await Task.Run<ChallengeResult>(() => new ChallengeResult("Facebook", props));
}
注:
はその後、私のコントローラ内の関連するメソッドは次のようになり。この時点でFacebookミドルウェアのSignInSchemeがどのように "Temp"であるかを覚えておいてください。それは "登録"アクションメソッドにリダイレクトされます。そこには、コードでのFacebookからClaimsPrincipleを抽出します。
var externalPrincipal = await HttpContext.Authentication.AuthenticateAsync("Temp");
この時点で、あなたが主張して行う必要があるものは何でも行うことができます。私はあなたが見ることができるように電子メールの主張を抽出します。また、CookiePrincipleをクッキーに保持するために、「Cookie」サインイン方式でサインインします。
そして?あなたはそれを働かせるか、どこに問題を起こしましたか?私たちに助けてくれるかもしれません... –
私たちは別の仕事の流れを決めました threxのためのthrx – Wasyster