从IdentityServer3登录页面中的客户端获取重定向链接 [英] Get redirect link from client in IdentityServer3 login page

查看:213
本文介绍了从IdentityServer3登录页面中的客户端获取重定向链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从登录页面中IdentityServer3的Identity中的客户端获取redirectUrl. 对于EX:我有一个"localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout"链接 当我点击它时,我将被重定向到IndentityServer中的登录页面,我需要获取上面的重定向链接(

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

这是我的客户端配置:

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

推荐答案

我不明白您为什么要在此处进行重定向.我看不出逻辑.

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

您已经阅读了identityServer3的文档吗?您将在此处看到

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

GET/connect/authorize?client_id = client1& scope = openid电子邮件api1& response_type = id_token令牌& redirect_uri = *链接: https://identityserver.github.io/Documentation/docsv2 /endpoints/authorization.html

这意味着,当您看到用户未登录时,会将其发送到身份服务器的登录页面(即使上面的HTTP GET方法链接到端点,身份服务器也会显示登录页面),并在登录页面的请求中发送重定向网址.只需确保该客户端允许使用重定向网址即可(请查看文档).

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.不建议将API和身份服务器保留在同一项目中!

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

这篇关于从IdentityServer3登录页面中的客户端获取重定向链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆