我将is4aspid模板用于IdentityServer4。服务器收到连接/授权请求后,称为AccountController.Login。题。我在哪里可以看到所有默认路由?登出示例?我可以改变这个吗?例如,何时收到一个名为OtherControl.MyLogin?的“连接/授权”?
答案 0 :(得分:0)
我可能在哪里看到所有默认路由?
有一个发现端点,用于检索有关您的IdentityServer的元数据。
它返回诸如发行者名称,密钥材料,支持的范围等信息,您可以在其中看到端点(令牌端点,userinfo端点等)。
运行IdentityServer应用程序时,可通过/.well-known/openid-configuration相对于基址使用发现端点,例如:
http://youridentityserver/.well-known/openid-configuration
注销示例?
"end_session_endpoint": "http://youridentityserver/connect/endsession",
我可以更改吗?
根据spec,您无法更改发现端点URL。
修改
但是我在哪里可以阅读有关此文件的官方文档?我可以改变这种行为吗?
研究文档后,我发现您可以使用UserInteraction选项来重新配置路由(我同意应该对它进行更好地记录)。
这意味着您可以设置自己的网址(用于LoginUrl,LogoutUrl,ConsentUrl,ErrorUrl )来重定向用户。
例如:
我开发了一个.Net Core应用程序,它根据默认的identityserver4配置将用户重定向到 / Account / Login 路由。
我想将用户重定向到 Test / NewLogin 路由以进行用户登录。因此,使用 UserInteraction 我可以在Startup.cs类中重新配置LoginUrl。
解决方案1:添加SetupIdentityServer选项方法
public void ConfigureServices(IServiceCollection services)
{
IIdentityServerBuilder builder = services.AddIdentityServer(SetupIdentityServer)
...
}
下面是SetupIdentityServer方法的实现:
private static void SetupIdentityServer(IdentityServer4.Configuration.IdentityServerOptions identityServerOptions)
{
identityServerOptions.UserInteraction.LoginUrl = "/Test/NewLogin";
}
解决方案2:使用此代码,我可以达到相同的结果
public void ConfigureServices(IServiceCollection services)
{
IIdentityServerBuilder builder = services.AddIdentityServer(options => options.UserInteraction.LoginUrl = "/Test/NewLogin"))
...
}
结果:
答案 1 :(得分:0)
我希望您在两年后找到答案,但如果其他人仍在寻找,IdentityServer4.Constants 中提供了默认路由路径 - 来源https://github.com/IdentityServer/IdentityServer4/blob/main/src/IdentityServer4/src/Constants.cs
此类包含名为 UIConstants、EndpointNames 和 ProtocolRoutePaths 的类,它们列出了所涉及的 URI 路径。
不幸的是,这仍然没有直接告诉您这些路径映射到哪些控制器操作,但它可能会让您更接近真相:
public static class UIConstants
{
// the limit after which old messages are purged
public const int CookieMessageThreshold = 2;
public static class DefaultRoutePathParams
{
public const string Error = "errorId";
public const string Login = "returnUrl";
public const string Consent = "returnUrl";
public const string Logout = "logoutId";
public const string EndSessionCallback = "endSessionId";
public const string Custom = "returnUrl";
public const string UserCode = "userCode";
}
public static class DefaultRoutePaths
{
public const string Login = "/account/login";
public const string Logout = "/account/logout";
public const string Consent = "/consent";
public const string Error = "/home/error";
public const string DeviceVerification = "/device";
}
}
public static class EndpointNames
{
public const string Authorize = "Authorize";
public const string Token = "Token";
public const string DeviceAuthorization = "DeviceAuthorization";
public const string Discovery = "Discovery";
public const string Introspection = "Introspection";
public const string Revocation = "Revocation";
public const string EndSession = "Endsession";
public const string CheckSession = "Checksession";
public const string UserInfo = "Userinfo";
}
public static class ProtocolRoutePaths
{
public const string ConnectPathPrefix = "connect";
public const string Authorize = ConnectPathPrefix + "/authorize";
public const string AuthorizeCallback = Authorize + "/callback";
public const string DiscoveryConfiguration = ".well-known/openid-configuration";
public const string DiscoveryWebKeys = DiscoveryConfiguration + "/jwks";
public const string Token = ConnectPathPrefix + "/token";
public const string Revocation = ConnectPathPrefix + "/revocation";
public const string UserInfo = ConnectPathPrefix + "/userinfo";
public const string Introspection = ConnectPathPrefix + "/introspect";
public const string EndSession = ConnectPathPrefix + "/endsession";
public const string EndSessionCallback = EndSession + "/callback";
public const string CheckSession = ConnectPathPrefix + "/checksession";
public const string DeviceAuthorization = ConnectPathPrefix + "/deviceauthorization";
public const string MtlsPathPrefix = ConnectPathPrefix + "/mtls";
public const string MtlsToken = MtlsPathPrefix + "/token";
public const string MtlsRevocation = MtlsPathPrefix + "/revocation";
public const string MtlsIntrospection = MtlsPathPrefix + "/introspect";
public const string MtlsDeviceAuthorization = MtlsPathPrefix + "/deviceauthorization";
public static readonly string[] CorsPaths =
{
DiscoveryConfiguration,
DiscoveryWebKeys,
Token,
UserInfo,
Revocation
};
}