2

Thinktecture Identity Server v3에서 Facebook으로 OAuth2 AssertionFlow를 구성 할 수 있습니까?Thinktecture Identity server v3 - Facebook 주장 흐름

Microsoft OAuth 및 AuthorizationServer에 대한 AssertionFlow 구현에 관한 leastprivilege.com에 대한 게시물이 있지만 Facebook과 통합해야하며 AuthorizationServer는 더 이상 사용되지 않는 것으로 표시되어 더 이상 유지 관리되지 않습니다.

답변

4

을, 나는 나의 작업 솔루션의 일부 코드를 게시

서버 사이드 - 사용자 정의 유효성 검사기를. :

public class FacebookCustomGrantValidator: ICustomGrantValidator 
    { 
     private readonly IUserService userService; 
     private const string _FACEBOOK_PROVIDER_NAME = "facebook"; 
     // ... 

     async Task<CustomGrantValidationResult> ICustomGrantValidator.ValidateAsync(ValidatedTokenRequest request) 
     { 
      // check assetion type (you can have more than one in your app) 
      if (request.GrantType != "assertion_fb") 
       return await Task.FromResult<CustomGrantValidationResult>(null); 

      // I assume that fb access token has been sent as a response form value (with 'assertion' key) 
      var fbAccessToken = request.Raw.Get("assertion"); 
      if (string.IsNullOrWhiteSpace(assertion)) 
       return await Task.FromResult<CustomGrantValidationResult>(new CustomGrantValidationResult 
       { 
        ErrorMessage = "Missing assertion." 
       }); 

      AuthenticateResult authebticationResult = null; 

      // if fb access token is invalid you won't be able to create Facebook client 
      var client = new Facebook.FacebookClient(fbAccessToken); 
      dynamic response = client.Get("me", new { fields = "email, first_name, last_name" }); 

      // create idsrv identity for the user 
      authebticationResult = await userService.AuthenticateExternalAsync(new ExternalIdentity() 
      { 
       Provider = _FACEBOOK_PROVIDER_NAME, 
       ProviderId = response.id, 
       Claims = new List<Claim> 
       { 
        new Claim("Email", response.email), 
        new Claim("FirstName", response.first_name), 
        new Claim("LastName", response.last_name) 
        // ... and so on... 
       } 
      }, 
      new SignInMessage()); 

      return new CustomGrantValidationResult 
      { 
       Principal = authebticationResult.User 
      }; 
     } 
    } 

쉽게도 (Thinktexture.IdentityModel 클라이언트 라이브러리 nuget 패키지) Thinktecture에 의해 제공됩니다 OAuth2Client로 테스트 할 수 있습니다.

string fbAccessToken = "facebook_access_token_you_aquired_while_logging_in"; 
string assertionType = "assertion_fb"; 

var client = new OAuth2Client(
        new Uri("your_auth_server_url"), 
        "idsrv_client_id", 
        "idsrv_client_secret"); 

string idsrvAccessToken = client.RequestAssertionAsync(assetionType, fbAccessToken,).Result; 
0

IdentityServer v3도 어설 션 흐름을 지원합니다. 샘플 위키가 (소위 "사용자 정의 보조금)에 두 개의 샘플이 있습니다 @ NathanAldenSr의 의견에

응답에서 https://github.com/thinktecture/Thinktecture.IdentityServer.v3.Samples/tree/master/source

+0

불행히도 FB로 작동시키는 방법을 알지 못합니다. 네이티브 클라이언트 측에서 fb 사용자 액세스 토큰을 가지고 있으며이를 어떻게 처리해야할지 모르겠습니다. 사용자 정의 흐름을 사용하여 IdentityServer로 보낼 수 있지만 다음은 무엇입니까? IdentityServer에서 어떻게해야합니까? 페이스 북은 순간에 단언 흐름을 지원합니까? – moody19871987

+0

idsrv -에서 FB 토큰의 유효성을 검사하고 시스템의 사용자를 나타내는 클레임 ​​주체로 전환해야합니다. – leastprivilege

+0

idsrv 쪽에서 facebook 액세스 토큰을 가지고 있으면 (fb api를 사용하여) 유효성을 확인하고 fb userId를 얻습니다. 그럼 내 데이터베이스에 대해 확인하고, 내 자신의 액세스 토큰을 생성하고 클라이언트에게 보낼 수 있습니다. 당신의 도움을 주셔서 감사합니다! – moody19871987

관련 문제