Lit*_*nny 7 model-view-controller authorization identityserver4
这是我的 mvc 与身份服务器连接的初始设置。
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
SignInAsAuthenticationType = "Cookies",
Authority = "http://identity.azurewebsites.net",
RedirectUri = "http://localhost:62419/signin-oidc",
PostLogoutRedirectUri = "http://localhost:62419/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);
}
}
});
Run Code Online (Sandbox Code Playgroud)
我可以访问身份服务器。我收到一条消息
抱歉,出现错误:unified_client Invalid redirect_uri
我已将 redirectUri 添加到与上面显示的代码匹配的 ClientRedirectUris 表中。有没有我忘记添加或设置的其他区域。
您必须确保重定向 url 与 IdentityServer 中客户端配置中的重定向 url 匹配。例如
new Client
{
ClientId = "mvc",
ClientName = "MVC Client",
AllowedGrantTypes = GrantTypes.Implicit,
// where to redirect to after login
RedirectUris = { "http://localhost:62419/signin-oidc" },
// where to redirect to after logout
PostLogoutRedirectUris = { "http://localhost:62419/signout-callback-oidc" },
AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
}
}
Run Code Online (Sandbox Code Playgroud)
确保RedirectUris匹配您客户端中设置的重定向 url ' http://localhost:62419/signin-oidc '
另外,请确保您的范围与客户端配置中的AllowedScopes 匹配。如果我们能够看到请求 URL,将会有所帮助。IE
https://identity.azurewebsites.net/connect/authorize?
client_id=mvc
&redirect_uri=http://localhost:62419/signin-oidc
&response_type=id_token
&scope=openid profile
&nonce=63653346343504
&state=CfDJAJDR
&response_mode=form_post
Run Code Online (Sandbox Code Playgroud)