...
app.UseOAuthAuthentication(new OAuthOptions
{
AuthenticationScheme = "LinkedIn",
DisplayName = "LinkedIn",
ClientId = Configuration["linkedin:clientId"],
ClientSecret = Configuration["linkedin:clientSecret"],
CallbackPath = new PathString("/signin-linkedin"),
AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization",
TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken",
UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,formatted-name,email-address,picture-url)",
Scope = { "r_basicprofile", "r_emailaddress", "w_share" },
Events = new OAuthEvents
{
OnTicketReceived = context =>
{
// Indicate that we handled the login
context.HandleResponse();
// Default redirect path is the base path
if (string.IsNullOrEmpty(context.ReturnUri))
{
context.ReturnUri = "/";
}
context.Response.Redirect(context.ReturnUri);
return Task.FromResult(0);
},
OnCreatingTicket = async context =>
{
// Retrieve user info
var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken);
request.Headers.Add("x-li-format", "json"); // Tell LinkedIn we want the result in JSON, otherwise it will return XML
var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted);
response.EnsureSuccessStatusCode();
// Do database stuff to find user using parameters provided through oauth
// Perform identity sign in using sign in manager
await signInManager.SignInAsync(dbUser, false);
}
}
});
app.Map("/login", builder =>
{
builder.Run(async context =>
{
// Return a challenge to invoke the LinkedIn authentication scheme
await context.Authentication.ChallengeAsync("LinkedIn", properties: new AuthenticationProperties() { RedirectUri = "/" });
});
});
그것은 단지 링크드 인 인증을위한 자신의 쿠키의 낙하 미들웨어를 방지 "OnTicketReceived"의 코드입니다.
나는 그 방법으로 작동하지 않아야한다고 확신한다 ... 로컬 계정과 다른 공급자 계정 ..... 보통 사용자가 처음 로그인 할 때 oauth를 사용할 때 로컬 사용자로 저장한다. , 그게 최선의 접근 방식이어야합니다 ... 아니면 혼합 된 접근 방식을 원할 경우, 사용자가 oauth를 통해 로그인 할 때 자신의 정보가 로컬 사용자 중 하나와 연결되어 있는지 확인하십시오 (예 경우). 그런 다음 팝업을 표시하십시오 oauth 정보를 로컬 계정에 연결하고 토큰 화 된 URL이 포함 된 전자 메일을 로컬 사용자에게 보내어 해당 연결을 승인할지 묻는 메시지가 나타납니다. 로컬 사용자> 보안을 위해 oauth를 승인합니다. – Hackerman
그게 내가 이해 한 것처럼, 지금까지 읽은 모든 예제가 어떻게 작동하는 것 같지 않다. (net core ...) – Paul
그래,이 중 하나에 대한 주제가 부족하다. ... 우리는 일반적으로 기본적인 것들을 발견합니다 ... oauth 패턴을 읽고 자신의 설계 결정을 내리고 자신의 버전을 만들기 시작합니다. 예를 들어 로컬 사용자로 저장할지 여부를 확인하거나 앱을 안전하게 유지하면서 로컬 사용자 ... https://tools.ietf.org/html/rfc6749 – Hackerman