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

Commit

Permalink
dynamically calculate IssuerUri when value not conifgured
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Jan 17, 2016
1 parent be16c77 commit 2e223fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

using IdentityModel.Constants;
using IdentityServer3.Core.Configuration;
using IdentityServer3.Core.Extensions;
using IdentityServer3.Core.Services;
using Microsoft.Owin;
using System;
using System.ComponentModel;
using System.IdentityModel.Metadata;
using System.IdentityModel.Protocols.WSTrust;
using System.IdentityModel.Tokens;
using System.Collections.Generic;

#pragma warning disable 1591

Expand All @@ -30,18 +34,35 @@ namespace IdentityServer3.WsFederation.ResponseHandling
public class MetadataResponseGenerator
{
private readonly IdentityServerOptions _options;
private readonly IDictionary<string, object> _environment;

public MetadataResponseGenerator(IdentityServerOptions options)
public MetadataResponseGenerator(IdentityServerOptions options, OwinEnvironmentService owin)
{
_options = options;
_environment = owin.Environment;
}

private string IssuerUri
{
get
{
var uri = _options.IssuerUri;
if (String.IsNullOrWhiteSpace(uri))
{
uri = _environment.GetIdentityServerBaseUrl();
if (uri.EndsWith("/")) uri = uri.Substring(0, uri.Length - 1);
}

return uri;
}
}

public EntityDescriptor Generate(string wsfedEndpoint)
{
var applicationDescriptor = GetApplicationDescriptor(wsfedEndpoint);
var tokenServiceDescriptor = GetTokenServiceDescriptor(wsfedEndpoint);

var id = new EntityId(_options.IssuerUri);
var id = new EntityId(IssuerUri);
var entity = new EntityDescriptor(id);
entity.SigningCredentials = new X509SigningCredentials(_options.SigningCertificate);
entity.RoleDescriptors.Add(applicationDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,28 @@ public class SignInResponseGenerator
private readonly static ILog Logger = LogProvider.GetCurrentClassLogger();
private readonly IdentityServerOptions _options;
private readonly IUserService _users;

public SignInResponseGenerator(IdentityServerOptions options, IUserService users)
private readonly IDictionary<string, object> _environment;

public SignInResponseGenerator(IdentityServerOptions options, IUserService users, OwinEnvironmentService owinEnvironment)
{
_options = options;
_users = users;
_environment = owinEnvironment.Environment;
}

private string IssuerUri
{
get
{
var uri = _options.IssuerUri;
if (String.IsNullOrWhiteSpace(uri))
{
uri = _environment.GetIdentityServerBaseUrl();
if (uri.EndsWith("/")) uri = uri.Substring(0, uri.Length - 1);
}

return uri;
}
}

public async Task<SignInResponseMessage> GenerateResponseAsync(SignInValidationResult validationResult)
Expand Down Expand Up @@ -178,7 +195,7 @@ private SecurityToken CreateSecurityToken(SignInValidationResult validationResul
ReplyToAddress = validationResult.ReplyUrl,
SigningCredentials = new X509SigningCredentials(_options.SigningCertificate, validationResult.RelyingParty.SignatureAlgorithm, validationResult.RelyingParty.DigestAlgorithm),
Subject = outgoingSubject,
TokenIssuerName = _options.IssuerUri,
TokenIssuerName = IssuerUri,
TokenType = validationResult.RelyingParty.TokenType
};

Expand Down

0 comments on commit 2e223fc

Please sign in to comment.