这里我们使用的是implicit这个flow(详细内容可以阅读ddrsql的IdentityServer4之Implicit(隐式许可)),它主要用于客户端应用程序(主要指基于javascript的应用),它允许客户端程序重定向到AuthorizationServer,然后带着token重定向回来。scopesscopes值得一提的是这里的ResponseType为"id_token token",表示既获取id_token也获取access_token。而SaveTokens设为true则表示要将从AuthorizationServer返回的token持久化在cookie之中,这样就不用每次都去请求token了。
当然,也还得在Configure方法中,配置Authentication中间件:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseAuthentication();
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
*.位置仍然需要在UseMvc之前。
在InMemoryConfiguration类中修改GetClients方法:
public static IEnumerable<Client> GetClients()
{
return new[]
{
new Client
{
ClientId = "client.api.service",
ClientSecrets = new [] { new Secret("clientsecret".Sha256()) },
AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
AllowedScopes = new [] { "clientservice" }
},
......,
new Client
{
ClientId = "cas.mvc.client.implicit",
ClientName = "CAS MVC Web App Client",
AllowedGrantTypes = GrantTypes.Implicit,
RedirectUris = { $"http://{Configuration["Clients:MvcClient:IP"]}:{Configuration["Clients:MvcClient:Port"]}/signin-oidc" },
PostLogoutRedirectUris = { $"http://{Configuration["Clients:MvcClient:IP"]}:{Configuration["Clients:MvcClient:Port"]}/signout-callback-oidc" },
AllowedScopes = new [] {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"agentservice", "clientservice", "productservice"
},
AllowAccessTokensViaBrowser = true // can return access_token to this client
}
};
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-92987-4.html
能打吗
接着就部署多款式无人机
渔民们走
孤独暗自泪下来