我想從登錄頁面中的IdentityServer3中的Identity中的客戶端獲取redirectUrl。對於EX: :我有一個「localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout」鏈接 當我點擊它時,我將被重定向到IndentityServer的登錄頁面,我需要重定向鏈接上述(http://localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout) 在從IdentityServer3登錄頁面中的客戶端獲取重定向鏈接
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",
});
});
}
感謝您的回覆。 我的情況是,當用戶通過鏈接(http:// localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout)結賬時,如果他們沒有簽名,我會將它們重定向到Identityserver登錄頁面,然後我需要重定向鏈接在IdentityServer端進行我的企業登錄,我可以在哪裏獲得Identityserver端客戶端的重定向鏈接? 謝謝 –
我不知道如何訪問身份服務器中的重定向鏈接。 但是我仍然相信,如果你做以下事情會更容易: 用戶來到一個頁面(或者進行web api調用) - >如果用戶登錄,檢查服務器端(在你的api中) - >獲取當前頁面url - >重定向用戶登錄並使當前頁面成爲重定向url。 (這樣,如果用戶登錄並進入支付鏈接,您將會遇到同樣的情況 您應該將業務邏輯分開,不要進入身份服務器。身份服務器應該不知道它提供身份的應用程序類型 – theCuriousOne