Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
add owin extensions for setting/getting request origin
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Oct 22, 2015
1 parent f4d7be3 commit 01f2446
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using System;
using IdentityServer3.Core.Extensions;

namespace Owin
Expand All @@ -34,7 +35,7 @@ public static IAppBuilder ConfigureIdentityServerBaseUrl(this IAppBuilder app, s
var origin = publicOrigin;
if (origin.IsMissing())
{
origin = request.Uri.Scheme + "://" + request.Host.Value;
origin = ctx.Environment.GetIdentityServerOrigin();
}

ctx.Environment.SetIdentityServerHost(origin);
Expand Down
5 changes: 3 additions & 2 deletions source/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,11 @@ public static class OwinEnvironment
{
public const string IdentityServerBasePath = "idsrv:IdentityServerBasePath";
public const string IdentityServerHost = "idsrv:IdentityServerHost";
public const string IdentityServerOrigin = "idsrv:IdentityServerOrigin";

public const string RequestId = "idsrv:RequestId";
public const string RequestId = "idsrv:RequestId";
}

public static class Authentication
{
public const string SigninId = "signinid";
Expand Down
36 changes: 36 additions & 0 deletions source/Core/Extensions/OwinEnvironmentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,42 @@ public static string GetRequestId(this IDictionary<string, object> env)
return null;
}

/// <summary>
/// Sets the origin for the current request.
/// </summary>
/// <param name="env">The OWIN environment.</param>
/// <param name="origin">The origin.</param>
/// <returns></returns>
public static void SetIdentityServerOrigin(this IDictionary<string, object> env, string origin)
{
if (env == null) throw new ArgumentNullException("env");

env[Constants.OwinEnvironment.IdentityServerOrigin] = origin;
}

/// <summary>
/// Gets the origin for the current request.
/// </summary>
/// <param name="env">The OWIN environment.</param>
/// <returns></returns>
public static string GetIdentityServerOrigin(this IDictionary<string, object> env)
{
if (env == null) throw new ArgumentNullException("env");

object value;
if (env.TryGetValue(Constants.OwinEnvironment.IdentityServerOrigin, out value))
{
var origin = value as string;
if (origin != null)
{
return origin.RemoveTrailingSlash();
}
}

var request = new OwinRequest(env);
return request.Uri.Scheme + "://" + request.Host.Value;
}

/// <summary>
/// Resolves dependency T from the IdentityServer DI system.
/// </summary>
Expand Down

0 comments on commit 01f2446

Please sign in to comment.