Thinktecture IdentityServer3 Facebook 登录按钮问题
Thinktecture IdentityServer3 Facebook Login Button Issue
我在我的项目中使用 "IdentityServer3 - IdentityManager - MembershipReboot" 进行用户管理、身份验证和资源授权。
我从下面的示例开始,在创建用户、通过 /connect/token api 对他们进行身份验证和授权资源方面做得很好。
https://github.com/thinktecture/Thinktecture.IdentityServer.v3.Samples/tree/master/source/MembershipReboot
我的解决方案的简要架构是
MySql 作为数据库。通过 MembershipReboot.EF 与 MembershipReboot 通信。
客户端项目使用html + angularjs开发。
资源 API 是使用 Nancy 开发的,并在单独的项目中托管在 Owin+Katana 上。
身份验证服务 (IdSvr+IdMgr+MR) 托管在一个单独的项目中。
现在我想创建一个简单的 button/link 单击它会引导我登录 facebook。此按钮的功能应与 IDSvr 默认登录页面中定义的相同(https://localhost:44333/core/login?signin=4f909a877cc465afd26d72f60ec08f51) "Facebook button".
我曾多次尝试在互联网上搜索,但 none 个案例符合我的情况。
我什至尝试复制默认 IdSvr facebook 登录的请求-响应行为,但这不起作用,因为 cookie 没有保存在终端客户端上。
我还尝试点击“https://localhost:44333/core/signin-facebook”并从服务器得到 HTTP/1.1 500 内部服务器错误 的响应。所以我想可能是我在 IdSrv 项目中设置 facebook 选项时出错了。
因此,如果有人可以向我提供一个 IdSvr API 来连接或告诉我如何配置 Id Svr,以便映射 url 可以将其重定向到 facebook 登录。或者可以告诉我在 IdSrv 中设置 facebook 身份验证选项时我哪里错了。
我的问题的简短答案是我正在寻找 url。
如果您想对此有更好的了解,请进一步阅读 url
经过大量的Hit&Trial & Study 努力,我找到了解决方案。好吧,我认为这个问题的根本原因是突然出现的新技术事物(Owin、Katana、OAuth、IdentityServer、IdentityManagement、MembershipReboot、Owin Facebook)以及理解它们的时间太少了。
我建议那些和我情况相同的人首先了解一下 OAuth。我发现下面 link 是一个简短而好的。
http://tutorials.jenkov.com/oauth2/index.html
在此之后我了解到,在我们的场景中,我们正在处理两个应用程序,因此需要处理两个身份验证。
用于将用户连接到 Facebook。我们在 developers.facebook.com
上创建了一个应用
用于将用户连接到 IdentityServer。我们在 AuthenticationServices 项目的 Clients.cs 文件中创建了一个客户端。
所以现在这是最终的解决方案。
localhost:44333 其中 AuthenticationService 是 运行
locahost:8088 其中前端服务 运行 正在调用 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");
授权成功后的facebook应用程序默认重定向到http://localhost:44333/signin-facebook。所以不需要在那里做任何改变。
最终在 http://localhost:8088/login/auth 成功验证后,您将获得 access_token(+ 其他一些参数)。从这里开始,您可以使用此令牌从资源服务器访问资源。
我在我的项目中使用 "IdentityServer3 - IdentityManager - MembershipReboot" 进行用户管理、身份验证和资源授权。
我从下面的示例开始,在创建用户、通过 /connect/token api 对他们进行身份验证和授权资源方面做得很好。 https://github.com/thinktecture/Thinktecture.IdentityServer.v3.Samples/tree/master/source/MembershipReboot
我的解决方案的简要架构是
MySql 作为数据库。通过 MembershipReboot.EF 与 MembershipReboot 通信。
客户端项目使用html + angularjs开发。
资源 API 是使用 Nancy 开发的,并在单独的项目中托管在 Owin+Katana 上。
身份验证服务 (IdSvr+IdMgr+MR) 托管在一个单独的项目中。
现在我想创建一个简单的 button/link 单击它会引导我登录 facebook。此按钮的功能应与 IDSvr 默认登录页面中定义的相同(https://localhost:44333/core/login?signin=4f909a877cc465afd26d72f60ec08f51) "Facebook button".
我曾多次尝试在互联网上搜索,但 none 个案例符合我的情况。 我什至尝试复制默认 IdSvr facebook 登录的请求-响应行为,但这不起作用,因为 cookie 没有保存在终端客户端上。
我还尝试点击“https://localhost:44333/core/signin-facebook”并从服务器得到 HTTP/1.1 500 内部服务器错误 的响应。所以我想可能是我在 IdSrv 项目中设置 facebook 选项时出错了。
因此,如果有人可以向我提供一个 IdSvr API 来连接或告诉我如何配置 Id Svr,以便映射 url 可以将其重定向到 facebook 登录。或者可以告诉我在 IdSrv 中设置 facebook 身份验证选项时我哪里错了。
我的问题的简短答案是我正在寻找 url。
如果您想对此有更好的了解,请进一步阅读 url
经过大量的Hit&Trial & Study 努力,我找到了解决方案。好吧,我认为这个问题的根本原因是突然出现的新技术事物(Owin、Katana、OAuth、IdentityServer、IdentityManagement、MembershipReboot、Owin Facebook)以及理解它们的时间太少了。
我建议那些和我情况相同的人首先了解一下 OAuth。我发现下面 link 是一个简短而好的。
http://tutorials.jenkov.com/oauth2/index.html
在此之后我了解到,在我们的场景中,我们正在处理两个应用程序,因此需要处理两个身份验证。
用于将用户连接到 Facebook。我们在 developers.facebook.com
上创建了一个应用
用于将用户连接到 IdentityServer。我们在 AuthenticationServices 项目的 Clients.cs 文件中创建了一个客户端。
所以现在这是最终的解决方案。 localhost:44333 其中 AuthenticationService 是 运行 locahost:8088 其中前端服务 运行 正在调用 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");
授权成功后的facebook应用程序默认重定向到http://localhost:44333/signin-facebook。所以不需要在那里做任何改变。
最终在 http://localhost:8088/login/auth 成功验证后,您将获得 access_token(+ 其他一些参数)。从这里开始,您可以使用此令牌从资源服务器访问资源。