【发布时间】:2019-11-25 18:47:59
【问题描述】:
我将 IdentityServer4 与 Asp.Net MVC(.net 框架)一起使用。授权时,我的站点可以导航到 Identity Server,但出现错误:客户端的授权类型无效。我该如何解决?给我这个组合的样本。非常感谢。
身份服务器客户端配置
{
"ClientId": "nfc",
"ClientName": ".net framework client",
// 5AF90EA2-CA6E-4AF9-AC1C-EAC72933D20D
"ClientSecrets": [ { "Value": "bBsQFRHNGCMB6W3EdybGe/lO8iOawFpeQ2ipC+nhGVM=" } ],
"AllowedGrantTypes": [ "client_credentials" ],
"AllowedScopes": [ "openid", "profile" ],
"AllowOfflineAccess": true,
"RedirectUris": [ "http://localhost:44398/signin-oidc" ],
"FrontChannelLogoutUris": [ "http://localhost:44398/signout-oidc" ],
"PostLogoutRedirectUris": [ "http://localhost:44398/signout-callback-oidc" ]
},
Asp.net 客户端启动.cs
[assembly: OwinStartup("ProductionConfiguration", typeof(NetFrameworkClient.Startup))]
namespace NetFrameworkClient
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions { });
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
SignInAsAuthenticationType = "Cookies",
Authority = "http://localhost:5000/",
RedirectUri = "http://localhost:44398/signin-oidc",
PostLogoutRedirectUri = "http://localhost:44398/signout-callback-oidc",
ClientId = "mvc",
ResponseType = "id_token",
Scope = "openid profile",
UseTokenLifetime = false,
RequireHttpsMetadata = false,
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = (context) =>
{
var identity = context.AuthenticationTicket.Identity;
var name = identity.Claims.FirstOrDefault(c => c.Type == identity.NameClaimType)?.Value;
return Task.FromResult(0);
}
}
});
}
}
}
在控制器上授权
[Authorize]
public ActionResult Index()
{
return View();
}
我得到的错误:抱歉,出现错误:未授权客户端 客户的授权类型无效
【问题讨论】: