Browse Source

Feature/identity server public origing to base url (#456)

* Add Tenant specific microsoft authentication

* Default no tenant in appsettings

* Adding access to graph to authorize reading profile

* Configure internal identityserver to use the BaseUrl as the PublicOrigin.
pull/456/merge
mhilgersom 6 years ago
committed by Sebastian Stehle
parent
commit
1dbaeebe7a
  1. 9
      backend/src/Squidex/Areas/IdentityServer/Config/IdentityServerServices.cs
  2. 1
      backend/src/Squidex/Config/Authentication/MicrosoftAuthenticationServices.cs
  3. 2
      backend/src/Squidex/Startup.cs

9
backend/src/Squidex/Areas/IdentityServer/Config/IdentityServerServices.cs

@ -15,6 +15,7 @@ using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.DataProtection.KeyManagement;
using Microsoft.AspNetCore.DataProtection.Repositories; using Microsoft.AspNetCore.DataProtection.Repositories;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Squidex.Domain.Users; using Squidex.Domain.Users;
@ -26,12 +27,14 @@ namespace Squidex.Areas.IdentityServer.Config
{ {
public static class IdentityServerServices public static class IdentityServerServices
{ {
public static void AddSquidexIdentityServer(this IServiceCollection services) public static void AddSquidexIdentityServer(this IServiceCollection services, IConfiguration config)
{ {
X509Certificate2 certificate; X509Certificate2 certificate;
var assembly = typeof(IdentityServerServices).Assembly; var assembly = typeof(IdentityServerServices).Assembly;
var urlsOptions = config.GetSection("urls").Get<UrlsOptions>();
using (var certificateStream = assembly.GetManifestResourceStream("Squidex.Areas.IdentityServer.Config.Cert.IdentityCert.pfx")) using (var certificateStream = assembly.GetManifestResourceStream("Squidex.Areas.IdentityServer.Config.Cert.IdentityCert.pfx"))
{ {
var certData = new byte[certificateStream!.Length]; var certData = new byte[certificateStream!.Length];
@ -74,6 +77,10 @@ namespace Squidex.Areas.IdentityServer.Config
services.AddIdentityServer(options => services.AddIdentityServer(options =>
{ {
options.UserInteraction.ErrorUrl = "/error/"; options.UserInteraction.ErrorUrl = "/error/";
if (!string.IsNullOrWhiteSpace(urlsOptions.BaseUrl))
{
options.PublicOrigin = urlsOptions.BaseUrl;
}
}) })
.AddAspNetIdentity<IdentityUser>() .AddAspNetIdentity<IdentityUser>()
.AddInMemoryApiResources(GetApiResources()) .AddInMemoryApiResources(GetApiResources())

1
backend/src/Squidex/Config/Authentication/MicrosoftAuthenticationServices.cs

@ -27,7 +27,6 @@ namespace Squidex.Config.Authentication
if (!string.IsNullOrEmpty(tenantId)) if (!string.IsNullOrEmpty(tenantId))
{ {
var resource = "https://graph.microsoft.com"; var resource = "https://graph.microsoft.com";
options.AuthorizationEndpoint = $"https://login.microsoftonline.com/{tenantId}/oauth2/authorize?resource={resource}"; options.AuthorizationEndpoint = $"https://login.microsoftonline.com/{tenantId}/oauth2/authorize?resource={resource}";
options.TokenEndpoint = $"https://login.microsoftonline.com/{tenantId}/oauth2/token?resource={resource}"; options.TokenEndpoint = $"https://login.microsoftonline.com/{tenantId}/oauth2/token?resource={resource}";
} }

2
backend/src/Squidex/Startup.cs

@ -54,7 +54,7 @@ namespace Squidex
services.AddSquidexHealthChecks(config); services.AddSquidexHealthChecks(config);
services.AddSquidexHistory(); services.AddSquidexHistory();
services.AddSquidexIdentity(config); services.AddSquidexIdentity(config);
services.AddSquidexIdentityServer(); services.AddSquidexIdentityServer(config);
services.AddSquidexInfrastructure(config); services.AddSquidexInfrastructure(config);
services.AddSquidexMigration(config); services.AddSquidexMigration(config);
services.AddSquidexNotifications(config); services.AddSquidexNotifications(config);

Loading…
Cancel
Save