Get redirect link from client in IdentityServer3 login page

给你一囗甜甜゛ 提交于 2019-12-11 06:17:35

问题


I would like to get redirectUrl from a client in Identity in IdentityServer3 in the login page. for EX: I have a "localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout" link when I hit it , I will be redirected to a login page in IndentityServer and I need to get redirect link above (http://localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout) in

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);
    }
}

here is my client configuration:

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",
            });
        });
    }

回答1:


I don't understand why would you want the redirect to happen there. I don't see the logic.

Have you read the documentation for identityServer3? You'll see there:

GET /connect/authorize?client_id=client1&scope=openid email api1&response_type=id_token token&redirect_uri=http://localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout

*link: https://identityserver.github.io/Documentation/docsv2/endpoints/authorization.html

It means, when you see that the user is not logged in you send him to the login page of your identity server (even though the HTTP GET method above links to an endpoint, the identity server will show a login page), and in the request to the login page you would send an redirect url. Just make sure the redirect url is allowed for that client (check the documentation).

p.s. It is not recommended to keep the API and the identity server in the same project!



来源:https://stackoverflow.com/questions/39487444/get-redirect-link-from-client-in-identityserver3-login-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!