我的问题的一个简短的答案是我正在寻找 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
在此之后,我了解到在我们的场景中,我们正在处理两个应用程序,因此是两个身份验证。
用于将用户连接到 Facebook。我们在developers.facebook.com 上创建了一个应用程序
用于将用户连接到 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");
成功授权后的 facebook 应用程序将默认重定向到http://localhost:44333/signin-facebook。所以不需要在那里做任何改变。
最后在http://localhost:8088/login/auth成功认证后你会得到 access_token(+ 一些其他参数)。从这里开始,您可以使用此令牌从资源服务器访问资源。