Skip to content

Commit

Permalink
OWIN use request uri when in active mode (#621)
Browse files Browse the repository at this point in the history
Fixes #549
  • Loading branch information
explunit authored and AndersAbel committed Mar 14, 2017
1 parent 60b8e33 commit b887027
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Expand Up @@ -71,6 +71,11 @@ protected override async Task ApplyResponseChallengeAsync()
// Don't serialize the RedirectUri twice.
challenge.Properties.RedirectUri = null;

if (redirectUri == null && Options.AuthenticationMode == AuthenticationMode.Active)
{
redirectUri = Context.Request.Uri.ToString();
}

var result = SignInCommand.Run(
idp,
redirectUri,
Expand Down
Expand Up @@ -688,6 +688,46 @@ public async Task KentorAuthServicesAuthenticationMiddleware_StoresAuthenticatio
new AuthenticationProperties(storedAuthnData.RelayData).Dictionary["test"].Should().Be("SomeValue");
}

[TestMethod]
public async Task KentorAuthServicesAuthenticationMiddleware_UsesReturnUrl_WhenActive()
{
var options = new KentorAuthServicesAuthenticationOptions(true);
options.AuthenticationMode = AuthenticationMode.Active;
var middleware = new KentorAuthServicesAuthenticationMiddleware(
new StubOwinMiddleware(401,
new AuthenticationResponseChallenge(
new string[] { "KentorAuthServices" }, new AuthenticationProperties() ) ),
CreateAppBuilder(),
options);

var context = OwinTestHelpers.CreateOwinContext();
context.Request.Host = new HostString("host3");
context.Request.Path = new PathString("/path3");
context.Request.QueryString = new QueryString("p1=value1");

await middleware.Invoke(context);
var storedAuthnData = ExtractRequestState(options.DataProtector, context);
storedAuthnData.ReturnUrl.Should().Be( "http://host3/path3?p1=value1" );
}

[TestMethod]
public async Task KentorAuthServicesAuthenticationMiddleware_UsesChallenge_WhenPassive()
{
var options = new KentorAuthServicesAuthenticationOptions(true);
options.AuthenticationMode = AuthenticationMode.Passive;
var middleware = new KentorAuthServicesAuthenticationMiddleware(
new StubOwinMiddleware(401,
new AuthenticationResponseChallenge(
new string[] { "KentorAuthServices" }, new AuthenticationProperties() ) ),
CreateAppBuilder(),
options);

var context = OwinTestHelpers.CreateOwinContext();
await middleware.Invoke(context);
var storedAuthnData = ExtractRequestState(options.DataProtector, context);
storedAuthnData.ReturnUrl.Should().BeNull();
}

[TestMethod]
public async Task KentorAuthServicesAuthenticationMiddleware_AcsUsesCommandResultLocation()
{
Expand Down

0 comments on commit b887027

Please sign in to comment.