我想从登录页面中IdentityServer3中Identity的客户端获取redirectUrl。 对于EX:我有一个" localhost:54483 / payments / 5466cdaa-2005-4947-b4dc-cc6a49b83dfd / checkout"链接 当我点击它时,我将被重定向到IndentityServer中的登录页面,我需要获得上面的重定向链接(http://localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout) 在
public class CustomViewService: DefaultViewService
{
private gtoken _gtoken;
public CustomViewService(DefaultViewServiceOptions config, IViewLoader viewLoader, gtoken gtoken) : base(config, viewLoader)
{
_gtoken = gtoken;
}
public override Task<Stream> Login(LoginViewModel model, SignInMessage message)
{
//TODO need to get redirect link here
return base.Login(model, message);
}
}
这是我的客户端配置:
public void Configuration(IAppBuilder app)
{
// turn off any default mapping on the JWT handler
AntiForgeryConfig.UniqueClaimTypeIdentifier = "sub";
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.Map("/api", idsrvApp =>
{
idsrvApp.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "http://localhost:5001",
ValidationMode = ValidationMode.Local, //set to validation endpoint if we want to support JWT revocation
RequiredScopes = new[] { "payment" }
});
});
Func<IOwinContext, bool> notApiRequest = (ctx) =>
{
return !ctx.Request.Path.StartsWithSegments(new PathString("/api"));
};
app.MapWhen(notApiRequest, idsrvApp =>
{
idsrvApp.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
CookieName = Constants.AUTH_COOKIE_NAME
});
idsrvApp.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "http://localhost:5001",
ClientId = "06de763b-ad15-4225-a147-9f7b5da61cdf",
RedirectUri = "mylocal",
ResponseType = "id_token",
Scope = "openid",
SignInAsAuthenticationType = "Cookies",
});
});
}
答案 0 :(得分:0)
我不明白你为什么要重定向发生在那里。我没有看到逻辑。
您是否阅读过identityServer3的文档?你会看到那里:
GET / connect / authorize?client_id = client1&amp; scope = openid email api1&amp; response_type = id_token token&amp; redirect_uri = http://localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout
* link:https://identityserver.github.io/Documentation/docsv2/endpoints/authorization.html
这意味着,当您看到用户未登录时,您将其发送到身份服务器的登录页面(即使上面的HTTP GET方法链接到端点,身份服务器也会显示登录页面),在登录页面的请求中,您将发送重定向网址。只需确保该客户端允许重定向URL(请查看文档)。
P.S。建议不要将API和身份服务器保留在同一个项目中!