신원을 사용하고 있습니다. 하지만 귀하의 질문은 어떻게 페이스 북 계정에서 클레임을 얻는 지에 관한 것이지, 어떻게 유지할 것인가에 관한 것이 아닙니다. 그래서 내가 도울 수 있기를 바란다. 나는 쿠키 미들웨어로 해냈다. ClaimsPrincipal을 Facebook에 로그인하는 것을 잡기 위해 '임시'쿠키 미들웨어를 추가 한 다음 강화 된 ClaimsPrincipal을 유지하기 위해 '진짜'쿠키 미들웨어에 로그인합니다. 시작 프로그램 클래스의 구성 방법에 코드의 관련 부분 다음 facebookOptions의 SignInScheme는 "온도"및 '임시'쿠키 미들웨어의 옵션이 얼마나
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);
참고가 false로 AutomaticAuthenticate있어이 (당신 때문에 Temp 쿠키에 ClaimsPrinciple을 자동으로 유지하고 싶지는 않지만 여기에 "쿠키"라고하는 실제 쿠키를 풍부하게 유지하고 싶습니다. 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이 "임시"상태임을 기억하십시오. '등록'작업 방법으로 리디렉션됩니다. 거기 당신은 코드와 페이스 북에서 ClaimsPrinciple를 추출 :
var externalPrincipal = await HttpContext.Authentication.AuthenticateAsync("Temp");
을 당신이 주장와 함께 할 필요가 무엇이든 할 수있는이 시점에서. 나는 당신이 볼 수있는 것처럼 전자 메일 클레임을 추출합니다. 클레임에 ClaimsPrinciple을 유지하기 위해 "쿠키"기호로 로그인합니다.
그리고? 일을 시작하게 만들었거나, 어디서나 문제를 겪었습니까? 우리가 도울 수 있을지 어쩌면 ... –
우리는 다른 작업 흐름을 결정했습니다 thöx aswer에 – Wasyster