2016-09-14 30 views
1

我想從登錄頁面中的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", 
      }); 
     }); 
    } 

回答

0

爲什麼你想重定向都發生在那裏我不明白。我沒有看到邏輯。

您是否閱讀過identityServer3的文檔?你會看到有:

GET /連接/授權的client_id =客戶端1 &範圍= OpenID的電子郵件API1 & RESPONSE_TYPE = id_token令牌& REDIRECT_URI = http://localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout

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

這意味着,當你看到用戶沒有登錄時,將他發送到你的身份服務器的登錄頁面(即使上面的HTTP GET方法鏈接到一個終端,身份服務器將顯示一個登錄頁面),並在請求登錄頁面,您將發送重定向url。只要確保該客戶端允許重定向url(請查看文檔)。

p.s.不建議將API和身份服務器保持在同一個項目中!

+0

感謝您的回覆。 我的情況是,當用戶通過鏈接(http:// localhost:54483/payments/5466cdaa-2005-4947-b4dc-cc6a49b83dfd/checkout)結賬時,如果他們沒有簽名,我會將它們重定向到Identityserver登錄頁面,然後我需要重定向鏈接在IdentityServer端進行我的企業登錄,我可以在哪裏獲得Identityserver端客戶端的重定向鏈接? 謝謝 –

+0

我不知道如何訪問身份服務器中的重定向鏈接。 但是我仍然相信,如果你做以下事情會更容易: 用戶來到一個頁面(或者進行web api調用) - >如果用戶登錄,檢查服務器端(在你的api中) - >獲取當前頁面url - >重定向用戶登錄並使當前頁面成爲重定向url。 (這樣,如果用戶登錄並進入支付鏈接,您將會遇到同樣的情況 您應該將業務邏輯分開,不要進入身份服務器。身份服務器應該不知道它提供身份的應用程序類型 – theCuriousOne