mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.2 KiB
60 lines
2.2 KiB
// ==========================================================================
|
|
// AuthenticationServices.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Config.Identity
|
|
{
|
|
public static class AuthenticationServices
|
|
{
|
|
public static void AddMyAuthentication(this IServiceCollection services, IConfiguration config)
|
|
{
|
|
var identityOptions = config.GetSection("identity").Get<MyIdentityOptions>();
|
|
|
|
services.AddAuthentication()
|
|
.AddMyGoogleAuthentication(identityOptions)
|
|
.AddMyMicrosoftAuthentication(identityOptions)
|
|
.AddMyApiProtection(identityOptions, config);
|
|
}
|
|
|
|
public static AuthenticationBuilder AddMyApiProtection(this AuthenticationBuilder authBuilder, MyIdentityOptions identityOptions, IConfiguration config)
|
|
{
|
|
var apiScope = Constants.ApiScope;
|
|
|
|
var urlsOptions = config.GetSection("urls").Get<MyUrlsOptions>();
|
|
|
|
if (!string.IsNullOrWhiteSpace(urlsOptions.BaseUrl))
|
|
{
|
|
string apiAuthorityUrl;
|
|
|
|
if (!string.IsNullOrWhiteSpace(identityOptions.AuthorityUrl))
|
|
{
|
|
apiAuthorityUrl = identityOptions.AuthorityUrl.BuildFullUrl(Constants.IdentityPrefix);
|
|
}
|
|
else
|
|
{
|
|
apiAuthorityUrl = urlsOptions.BuildUrl(Constants.IdentityPrefix);
|
|
}
|
|
|
|
authBuilder.AddIdentityServerAuthentication(options =>
|
|
{
|
|
options.Authority = apiAuthorityUrl;
|
|
options.ApiName = apiScope;
|
|
options.ApiSecret = null;
|
|
options.RequireHttpsMetadata = identityOptions.RequiresHttps;
|
|
});
|
|
}
|
|
|
|
return authBuilder;
|
|
}
|
|
}
|
|
}
|
|
|