简体   繁体   中英

Changing ReturnUrl in OWIN RedirectToIdentityProvider notification

We are currently overriding WSFederationAuthenticationModule.RedirectToIdentityProvider in our product to change the returnUrl to which the users agent is redirected to after authentication.

Now we're in the proces of adopting OWIN (Katana) middleware instead of HttpModules. In the RedirectToIdentityProvider notification in WsFederationAuthenticationOptions , I see the WCtx parameter now contains a WsFedOwinState parameter which is encrypted using DPAPI.

How do I implement the RedirectToIdentityProvider action to change the return URL? Do I need to decrypt the WsFedOwinState parameter to add the returnUrl query parameter or is there some other way?

inside RedirectToIdentityProvider, you will have access to the WsFederationMessage.

Set the Wreply property to the value you need.

As a note: MachineKey is used by default, not DPAPI for protecting wctx.

In my case, I changed the return URL in SecurityTokenValidated and had the redirection from ADFS always go to the same URL

 public void ConfigureAuth(IAppBuilder app)
{
    app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);

    app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType });

    app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
    {
        Wtrealm = realm,
        MetadataAddress = adfsMetadata,
        Notifications = new WsFederationAuthenticationNotifications
        {
            SecurityTokenValidated = nx =>
            {
                nx.AuthenticationTicket.Properties.RedirectUri = "/RedirectionGoesHere.aspx";
                return Task.FromResult(0);
            }
        }
    });
    // This makes any middleware defined above this line run before the Authorization rule is applied in web.config
    app.UseStageMarker(PipelineStage.Authenticate);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM