Thinktecture Identity Server v3-Facebook断言流程

moody19871987

是否可以在Thinktecture Identity Server v3中使用Facebook配置OAuth2 AssertionFlow?

minimumprivilege.com上有一关于为Microsoft OAuth和AuthorizationServer实现AssertionFlow的帖子,但是我需要与Facebook集成,此外,AuthorizationServer被标记为已弃用,并且不再维护。

moody19871987

为了响应@NathanAldenSr的评论,我发布了一些我的工作解决方案的代码。

服务器端-自定义验证器:

    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
            };
        }
    }

您可以使用Thinktecture也提供的OAuth2Client(在Thinktexture.IdentityModel客户端库nuget包中)轻松对其进行测试。

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;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Thinktecture Identity Server v3-Facebook断言流程

来自分类Dev

Thinktecture Identity Server 3单一注销

来自分类Dev

Thinktecture的Identity Server v3的ASP.NET MVC ViewService

来自分类Dev

Thinktecture Identity Server v3如何避免来自外部提供商的索赔?

来自分类Dev

Thinktecture Identity Server HRD

来自分类Dev

如何使用ASP.NET Identity设置Thinktecture Identity Server v3 beta 1-2?

来自分类Dev

Thinktecture Identity Server的可能方案?

来自分类Dev

使用ASP.NET Identity v2的Thinktecture Identity Server v2

来自分类Dev

解码ThinkTecture Identity Server JWT令牌

来自分类Dev

Thinktecture Identity Server密码重置重定向

来自分类Dev

Thinktecture Identity Sever v3与授权服务器之间如何集成?

来自分类Dev

Thinktecture Identity Server 3 Asp.Net身份示例,不断获得401授权被拒绝

来自分类Dev

Thinktecture Identity Server 3:用于保护WEB API免受未授权访问的客户端机密

来自分类Dev

WIF (using Thinktecture Identity Server) and Duplex WCF Channels

来自分类Dev

Thinktecture Identity Server客户端选择和实现

来自分类Dev

WIF(使用Thinktecture Identity Server)和双工WCF通道

来自分类Dev

具有OAuth隐式登录功能的Thinktecture Identity Server

来自分类Dev

Thinktecture Identity Server:保护Web API(授权最佳方法)

来自分类Dev

Guidance on Thinktecture IdentityServer v3 - certificates

来自分类Dev

Thinktecture IdentityServer V3管理页面

来自分类Dev

Thinktecture IdentityServer V3管理页面

来自分类Dev

Thinktecture IdentityServer v3指南-证书

来自分类Dev

Identity Server v3仅作为联合身份验证网关

来自分类Dev

如何配置Identity Server v3仅可登录一次,持续30天?

来自分类Dev

如何在Thinktecture IdentityServer v3中启用日志记录?

来自分类Dev

来自OpenIdConnect提供程序的配置文件数据-Thinktecture IdentityServer V3

来自分类Dev

Thinktecture Identity服务器与授权服务器

来自分类Dev

如何在AspNetIdentity中使用Thinktecture Identity Manager

来自分类Dev

chrome.identity和YouTube v3 API?

Related 相关文章

  1. 1

    Thinktecture Identity Server v3-Facebook断言流程

  2. 2

    Thinktecture Identity Server 3单一注销

  3. 3

    Thinktecture的Identity Server v3的ASP.NET MVC ViewService

  4. 4

    Thinktecture Identity Server v3如何避免来自外部提供商的索赔?

  5. 5

    Thinktecture Identity Server HRD

  6. 6

    如何使用ASP.NET Identity设置Thinktecture Identity Server v3 beta 1-2?

  7. 7

    Thinktecture Identity Server的可能方案?

  8. 8

    使用ASP.NET Identity v2的Thinktecture Identity Server v2

  9. 9

    解码ThinkTecture Identity Server JWT令牌

  10. 10

    Thinktecture Identity Server密码重置重定向

  11. 11

    Thinktecture Identity Sever v3与授权服务器之间如何集成?

  12. 12

    Thinktecture Identity Server 3 Asp.Net身份示例,不断获得401授权被拒绝

  13. 13

    Thinktecture Identity Server 3:用于保护WEB API免受未授权访问的客户端机密

  14. 14

    WIF (using Thinktecture Identity Server) and Duplex WCF Channels

  15. 15

    Thinktecture Identity Server客户端选择和实现

  16. 16

    WIF(使用Thinktecture Identity Server)和双工WCF通道

  17. 17

    具有OAuth隐式登录功能的Thinktecture Identity Server

  18. 18

    Thinktecture Identity Server:保护Web API(授权最佳方法)

  19. 19

    Guidance on Thinktecture IdentityServer v3 - certificates

  20. 20

    Thinktecture IdentityServer V3管理页面

  21. 21

    Thinktecture IdentityServer V3管理页面

  22. 22

    Thinktecture IdentityServer v3指南-证书

  23. 23

    Identity Server v3仅作为联合身份验证网关

  24. 24

    如何配置Identity Server v3仅可登录一次,持续30天?

  25. 25

    如何在Thinktecture IdentityServer v3中启用日志记录?

  26. 26

    来自OpenIdConnect提供程序的配置文件数据-Thinktecture IdentityServer V3

  27. 27

    Thinktecture Identity服务器与授权服务器

  28. 28

    如何在AspNetIdentity中使用Thinktecture Identity Manager

  29. 29

    chrome.identity和YouTube v3 API?

热门标签

归档