OIDC
This commit is contained in:
@@ -12,5 +12,15 @@ public static class AuthEnvironment
|
||||
public const string AdfsHomeRealm = "ADFS_WHR";
|
||||
public const string AdfsAuthType = "ADFS_WAUTH";
|
||||
public const string AdfsValidIssuers = "ADFS_VALID_ISSUERS";
|
||||
|
||||
public const string OidcAuthority = "OIDC_AUTHORITY";
|
||||
public const string OidcClientId = "OIDC_CLIENT_ID";
|
||||
public const string OidcClientSecret = "OIDC_CLIENT_SECRET";
|
||||
public const string OidcCallbackPath = "OIDC_CALLBACK_PATH";
|
||||
public const string OidcSignedOutCallbackPath = "OIDC_SIGNOUT_CALLBACK_PATH";
|
||||
public const string OidcScopes = "OIDC_SCOPES";
|
||||
public const string OidcRoleClaimType = "OIDC_ROLE_CLAIM_TYPE";
|
||||
public const string OidcNameClaimType = "OIDC_NAME_CLAIM_TYPE";
|
||||
public const string OidcValidIssuers = "OIDC_VALID_ISSUERS";
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,11 @@ public sealed class AdminRoleClaimsTransformation : IClaimsTransformation
|
||||
{
|
||||
"groups",
|
||||
"group",
|
||||
"role",
|
||||
"roles",
|
||||
ClaimTypes.GroupSid,
|
||||
ClaimTypes.Role,
|
||||
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role",
|
||||
"http://schemas.xmlsoap.org/claims/Group"
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using maintenance.Authentication.Abstractions;
|
||||
using maintenance.Authentication.Configuration;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace maintenance.Authentication.Providers.Oidc;
|
||||
|
||||
@@ -14,8 +16,61 @@ public sealed class OidcAuthProvider : IAuthProvider
|
||||
AuthenticationBuilder builder,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
throw new NotSupportedException(
|
||||
"OIDC provider is not implemented yet. Set AUTH_MODE=WSFED for current deployment.");
|
||||
var authority = configuration[AuthEnvironment.OidcAuthority];
|
||||
var clientId = configuration[AuthEnvironment.OidcClientId];
|
||||
var clientSecret = configuration[AuthEnvironment.OidcClientSecret];
|
||||
var callbackPath = configuration[AuthEnvironment.OidcCallbackPath] ?? "/signin-oidc";
|
||||
var signedOutCallbackPath = configuration[AuthEnvironment.OidcSignedOutCallbackPath] ?? "/signout-callback-oidc";
|
||||
var scopes = (configuration[AuthEnvironment.OidcScopes] ?? "openid;profile;email;role")
|
||||
.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
var roleClaimType = configuration[AuthEnvironment.OidcRoleClaimType]
|
||||
?? "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
|
||||
var nameClaimType = configuration[AuthEnvironment.OidcNameClaimType]
|
||||
?? "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name";
|
||||
var configuredValidIssuers = configuration[AuthEnvironment.OidcValidIssuers];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(authority))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Missing required configuration: {AuthEnvironment.OidcAuthority}");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(clientId))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Missing required configuration: {AuthEnvironment.OidcClientId}");
|
||||
}
|
||||
|
||||
return builder.AddOpenIdConnect(Scheme, options =>
|
||||
{
|
||||
options.Authority = authority;
|
||||
options.ClientId = clientId;
|
||||
options.ClientSecret = clientSecret;
|
||||
options.CallbackPath = callbackPath;
|
||||
options.SignedOutCallbackPath = signedOutCallbackPath;
|
||||
options.ResponseType = "code";
|
||||
options.SaveTokens = true;
|
||||
options.GetClaimsFromUserInfoEndpoint = true;
|
||||
|
||||
options.Scope.Clear();
|
||||
foreach (var scope in scopes)
|
||||
{
|
||||
options.Scope.Add(scope);
|
||||
}
|
||||
|
||||
var validIssuers = configuredValidIssuers?
|
||||
.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Where(v => !string.IsNullOrWhiteSpace(v))
|
||||
.ToArray();
|
||||
|
||||
options.TokenValidationParameters = new TokenValidationParameters
|
||||
{
|
||||
ValidateIssuer = validIssuers is { Length: > 0 },
|
||||
ValidIssuers = validIssuers,
|
||||
NameClaimType = nameClaimType,
|
||||
RoleClaimType = roleClaimType
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,15 @@
|
||||
"ADFS_WHR": "",
|
||||
"ADFS_WAUTH": "",
|
||||
"ADFS_CALLBACK_PATH": "/signin-wsfed",
|
||||
"OIDC_AUTHORITY": "https://adfs.example.com/adfs",
|
||||
"OIDC_CLIENT_ID": "CHANGE_ME",
|
||||
"OIDC_CLIENT_SECRET": "CHANGE_ME",
|
||||
"OIDC_CALLBACK_PATH": "/signin-oidc",
|
||||
"OIDC_SIGNOUT_CALLBACK_PATH": "/signout-callback-oidc",
|
||||
"OIDC_SCOPES": "openid;profile;email;role",
|
||||
"OIDC_ROLE_CLAIM_TYPE": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role",
|
||||
"OIDC_NAME_CLAIM_TYPE": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
|
||||
"OIDC_VALID_ISSUERS": "",
|
||||
"ConnectionStrings": {
|
||||
"PrimaryDb": "Server=localhost;Database=maintenance;User Id=svc_errorpages;Password=CHANGE_ME;TrustServerCertificate=True",
|
||||
"GroupLookupDb": "Server=localhost;Database=GroupLookup;User Id=svc_errorpages;Password=CHANGE_ME;TrustServerCertificate=True"
|
||||
|
||||
@@ -8,6 +8,15 @@
|
||||
"ADFS_WHR": "https://adfs.t.g:44373",
|
||||
"ADFS_WAUTH": "urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient",
|
||||
"ADFS_CALLBACK_PATH": "/signin-wsfed",
|
||||
"OIDC_AUTHORITY": "https://adfs.omb.gov/adfs",
|
||||
"OIDC_CLIENT_ID": "CHANGE_ME",
|
||||
"OIDC_CLIENT_SECRET": "CHANGE_ME",
|
||||
"OIDC_CALLBACK_PATH": "/signin-oidc",
|
||||
"OIDC_SIGNOUT_CALLBACK_PATH": "/signout-callback-oidc",
|
||||
"OIDC_SCOPES": "openid;profile;email;role",
|
||||
"OIDC_ROLE_CLAIM_TYPE": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role",
|
||||
"OIDC_NAME_CLAIM_TYPE": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
|
||||
"OIDC_VALID_ISSUERS": "",
|
||||
"ConnectionStrings": {
|
||||
"PrimaryDb": "Server=localhost;Database=maintenance;User Id=svc_errorpages;Password=CHANGE_ME;TrustServerCertificate=True",
|
||||
"GroupLookupDb": "Server=localhost;Database=GroupLookup;User Id=svc_errorpages;Password=CHANGE_ME;TrustServerCertificate=True"
|
||||
|
||||
Reference in New Issue
Block a user