Thinktecture IdentityServer3 Facebook登录按钮问题

时间:2015-05-12 16:33:27

标签: facebook identity-management identityserver3 membershipreboot

我在我的项目中使用“IdentityServer3 - IdentityManager - MembershipReboot”进行用户管理,身份验证&资源授权。

我从下面的示例开始,已经很好地创建用户,通过 / connect / token api和授权资源对它们进行身份验证。 https://github.com/thinktecture/Thinktecture.IdentityServer.v3.Samples/tree/master/source/MembershipReboot

我的解决方案的简要架构是

  1. MySql作为数据库。通过MembershipReboot.EF与MembershipReboot进行通信。

  2. 客户端项目使用html + angularjs开发。

  3. 资源API是使用Nancy& Sons开发的。在Owin + Katana的一个单独的项目中举办。

  4. 身份验证服务(IdSvr + IdMgr + MR)托管在一个单独的项目中。

  5. 现在我想创建一个简单的按钮/链接点击,这将导致我登录facebook。此按钮的功能应与IDSvr默认登录页面(https://localhost:44333/core/login?signin=4f909a877cc465afd26d72f60ec08f51)“Facebook按钮”中定义的相同。

    我已经尝试过google上网,但没有一个案例符合我的情况。 我甚至试图复制默认IdSvr facebook登录的请求 - 响应行为,但这不起作用,因为cookie没有保存在终端客户端上。

    此外,我尝试点击“https://localhost:44333/core/signin-facebook”并从服务器获得 HTTP / 1.1 500内部服务器错误的响应。所以我认为在IdSrv项目中设置Facebook选项可能会出错。

    因此,如果有人可以只提供一个IdSvr API来连接或告诉我如何配置Id Svr,以便映射网址可以将其重定向到Facebook登录。或者可以告诉我在IdSrv中设置facebook身份验证选项时我错了。

1 个答案:

答案 0 :(得分:3)

我的问题的简短答案是我正在寻找网址。

https://localhost:44333/connect/authorize?client_id=implicitclient&response_type=token&scope=read&redirect_uri=http://localhost:8088/login/auth&nonce=random_nonce&acr_values=idp%3AFacebook&response_mode=form_post

如果您想更好地了解此网址,请进一步阅读

经过大量的Hit& Trial&学习努力,我已经得到了解决方案。好吧,我认为这个问题的根本原因是突然出现的新技术(Owin,Katana,OAuth,IdentityServer,IdentityManagement,MembershipReboot,Owin Facebook)以及一点点了解它们。

我会建议那些和我情况相同的人首先了解OAuth。我发现下面的链接是一个简短的链接。

http://tutorials.jenkov.com/oauth2/index.html

在此之后,我了解到在我们的场景中,我们正在处理两个应用程序,因此进行了两次身份验证。

  1. 用于将用户连接到Facebook。我们在developers.facebook.com上创建了一个应用程序

  2. 用于将用户连接到IdentityServer。我们在AuthenticationServices项目的Clients.cs文件中创建了一个客户端。

  3. 所以现在这是最终的解决方案。 localhost:44333,其中AuthenticationService正在运行 locahost:8088正在运行FrontEnd服务,它正在调用AuthenticationService。

    <强> 1。在AuthenticationServices中创建客户端应用程序,如下所示

                new Client
                {
                    ClientName = "Implicit Clients",
                    Enabled = true,
                    ClientId = "implicitclient",
                    ClientSecrets = new List<ClientSecret>{
                        new ClientSecret("secret".Sha256())
                    },
                    Flow = Flows.Implicit,
                    RequireConsent = true,
                    AllowRememberConsent = true,
    
                    RedirectUris = new List<string>
                    {
                        "http://localhost:8088/login/auth" //This should be redirect url you want to hit after your app(not facebook app) redirects. 
                    },
    
                    ScopeRestrictions = new List<string>
                    { 
                        Constants.StandardScopes.OpenId,
                        Constants.StandardScopes.Profile,
                        Constants.StandardScopes.Email,
                        "read",
                        "write",
                    },
    
                    //SubjectType = SubjectTypes.Global,
                    AccessTokenType = AccessTokenType.Jwt,
    
                    IdentityTokenLifetime = 360,
                    AccessTokenLifetime = 360,
                },
    

    2创建以下授权网址

         var client = new OAuth2Client(new Uri("https://localhost:44333/core/connect/authorize"));
            var startUrl = client.CreateAuthorizeUrl(
                clientId: "implicitclient",
                responseType: "token",
                scope: "read",
                redirectUri: "http://localhost:8088/login/auth",
                nonce: "random_nonce",
                responseMode: "form_post",
                acrValues: "idp:Facebook");
    
    1. 成功授权后的Facebook应用会将默认值重定向为http://localhost:44333/signin-facebook。所以不需要在那里做任何改变。

    2. 最后在http://localhost:8088/login/auth上,您将在成功验证后获得access_token(+其他一些参数)。此后,您可以使用此令牌从资源服务器访问资源。