diff --git a/source/WsFederationPlugin/ResponseHandling/MetadataResponseGenerator.cs b/source/WsFederationPlugin/ResponseHandling/MetadataResponseGenerator.cs index added33..154d02b 100644 --- a/source/WsFederationPlugin/ResponseHandling/MetadataResponseGenerator.cs +++ b/source/WsFederationPlugin/ResponseHandling/MetadataResponseGenerator.cs @@ -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 @@ -30,10 +34,27 @@ namespace IdentityServer3.WsFederation.ResponseHandling public class MetadataResponseGenerator { private readonly IdentityServerOptions _options; + private readonly IDictionary _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) @@ -41,7 +62,7 @@ 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); diff --git a/source/WsFederationPlugin/ResponseHandling/SignInResponseGenerator.cs b/source/WsFederationPlugin/ResponseHandling/SignInResponseGenerator.cs index 7eab079..9ddfd98 100644 --- a/source/WsFederationPlugin/ResponseHandling/SignInResponseGenerator.cs +++ b/source/WsFederationPlugin/ResponseHandling/SignInResponseGenerator.cs @@ -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 _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 GenerateResponseAsync(SignInValidationResult validationResult) @@ -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 };