Skip to content
This repository has been archived by the owner on Dec 14, 2017. It is now read-only.

Set the RedirectUri dynamically #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions source/Clients/MVC OWIN Client (Hybrid)/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void Configuration(IAppBuilder app)
{
ClientId = "mvc.owin.hybrid",
Authority = Constants.BaseAddress,
RedirectUri = "https://localhost:44300/",
PostLogoutRedirectUri = "https://localhost:44300/",
//RedirectUri = "https://localhost:44300/",
//PostLogoutRedirectUri = "https://localhost:44300/",
ResponseType = "code id_token",
Scope = "openid profile read write offline_access",

Expand All @@ -53,6 +53,11 @@ public void Configuration(IAppBuilder app)
Constants.TokenEndpoint,
"mvc.owin.hybrid",
"secret");

if (String.IsNullOrEmpty(n.RedirectUri))
{
n.RedirectUri = n.Request.Scheme + "://" + n.Request.Host + n.Request.PathBase;
}

var tokenResponse = await tokenClient.RequestAuthorizationCodeAsync(
n.Code, n.RedirectUri);
Expand Down Expand Up @@ -81,6 +86,12 @@ public void Configuration(IAppBuilder app)

RedirectToIdentityProvider = n =>
{
// This ensures that the address used for sign in and sign out is picked up dynamically from the request
// this allows you to deploy the app (to Azure Web Sites, for example) without having to change settings.
var appBaseUrl = n.Request.Scheme + "://" + n.Request.Host + n.Request.PathBase;
n.ProtocolMessage.RedirectUri = appBaseUrl;
n.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;

// if signing out, add the id_token_hint
if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)
{
Expand All @@ -99,4 +110,4 @@ public void Configuration(IAppBuilder app)
});
}
}
}
}