0

我在我的项目中使用“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 开发的,并在一个单独的项目中托管在 Owin+Katana 上。

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

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

我已经尝试了很多谷歌搜索,但没有一个案例与我的场景相匹配。我什至尝试复制默认 IdSvr facebook 登录的请求-响应行为,但这不起作用,因为 cookie 没有保存在最终客户端上。

我还尝试点击“ https://localhost:44333/core/signin-facebook ”并从服务器获取响应为HTTP/1.1 500 Internal Server Error。所以我认为我在 IdSrv 项目中设置 facebook 选项时可能是错误的。

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

4

1 回答 1

3

我的问题的一个简短的答案是我正在寻找 url。

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 & Study 努力,我已经找到了解决方案。好吧,我认为这个问题的根本原因是突然出现的新技术(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 文件中创建了一个客户端。

所以现在这是最终的解决方案。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 创建授权 URL 如下

     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(+ 一些其他参数)。从这里开始,您可以使用此令牌从资源服务器访问资源。

于 2015-05-15T11:23:55.550 回答