2020-09-04 10:42:47 -04:00
|
|
|
|
using System;
|
2021-02-10 12:00:12 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2020-09-04 10:42:47 -04:00
|
|
|
|
using Bit.Core.Enums;
|
|
|
|
|
|
using Bit.Core.Sso;
|
2020-09-29 17:06:17 -04:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
2020-09-04 10:42:47 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Models.Data
|
|
|
|
|
|
{
|
|
|
|
|
|
public class SsoConfigurationData
|
|
|
|
|
|
{
|
|
|
|
|
|
private const string _oidcSigninPath = "/oidc-signin";
|
|
|
|
|
|
private const string _oidcSignedOutPath = "/oidc-signedout";
|
|
|
|
|
|
private const string _saml2ModulePath = "/saml2";
|
|
|
|
|
|
|
|
|
|
|
|
public SsoType ConfigType { get; set; }
|
|
|
|
|
|
|
2021-10-25 15:09:14 +02:00
|
|
|
|
// Crypto Agent
|
|
|
|
|
|
public bool UseCryptoAgent { get; set; }
|
|
|
|
|
|
public string CryptoAgentUrl { get; set; }
|
|
|
|
|
|
|
2020-09-04 10:42:47 -04:00
|
|
|
|
// OIDC
|
|
|
|
|
|
public string Authority { get; set; }
|
|
|
|
|
|
public string ClientId { get; set; }
|
|
|
|
|
|
public string ClientSecret { get; set; }
|
|
|
|
|
|
public string MetadataAddress { get; set; }
|
2020-09-29 17:06:17 -04:00
|
|
|
|
public OpenIdConnectRedirectBehavior RedirectBehavior { get; set; } = OpenIdConnectRedirectBehavior.FormPost;
|
2020-09-04 10:42:47 -04:00
|
|
|
|
public bool GetClaimsFromUserInfoEndpoint { get; set; }
|
2021-02-10 12:00:12 -05:00
|
|
|
|
public string AdditionalScopes { get; set; }
|
|
|
|
|
|
public string AdditionalUserIdClaimTypes { get; set; }
|
|
|
|
|
|
public string AdditionalEmailClaimTypes { get; set; }
|
|
|
|
|
|
public string AdditionalNameClaimTypes { get; set; }
|
|
|
|
|
|
public string AcrValues { get; set; }
|
2021-04-27 15:17:03 -04:00
|
|
|
|
public string ExpectedReturnAcrValue { get; set; }
|
2020-09-04 10:42:47 -04:00
|
|
|
|
|
|
|
|
|
|
// SAML2 IDP
|
|
|
|
|
|
public string IdpEntityId { get; set; }
|
|
|
|
|
|
public string IdpSingleSignOnServiceUrl { get; set; }
|
|
|
|
|
|
public string IdpSingleLogoutServiceUrl { get; set; }
|
|
|
|
|
|
public string IdpX509PublicCert { get; set; }
|
2021-10-06 19:36:03 +02:00
|
|
|
|
public Saml2BindingType IdpBindingType { get; set; } = Saml2BindingType.HttpRedirect;
|
2020-09-04 10:42:47 -04:00
|
|
|
|
public bool IdpAllowUnsolicitedAuthnResponse { get; set; }
|
|
|
|
|
|
public string IdpArtifactResolutionServiceUrl { get; set; }
|
|
|
|
|
|
public bool IdpDisableOutboundLogoutRequests { get; set; }
|
2021-10-06 19:36:03 +02:00
|
|
|
|
public string IdpOutboundSigningAlgorithm { get; set; } = SamlSigningAlgorithms.Sha256;
|
2020-09-04 10:42:47 -04:00
|
|
|
|
public bool IdpWantAuthnRequestsSigned { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
// SAML2 SP
|
|
|
|
|
|
public Saml2NameIdFormat SpNameIdFormat { get; set; } = Saml2NameIdFormat.Persistent;
|
|
|
|
|
|
public string SpOutboundSigningAlgorithm { get; set; } = SamlSigningAlgorithms.Sha256;
|
|
|
|
|
|
public Saml2SigningBehavior SpSigningBehavior { get; set; } = Saml2SigningBehavior.IfIdpWantAuthnRequestsSigned;
|
|
|
|
|
|
public bool SpWantAssertionsSigned { get; set; }
|
|
|
|
|
|
public bool SpValidateCertificates { get; set; }
|
2020-12-18 11:26:52 -05:00
|
|
|
|
public string SpMinIncomingSigningAlgorithm { get; set; } = SamlSigningAlgorithms.Sha256;
|
2020-09-04 10:42:47 -04:00
|
|
|
|
|
|
|
|
|
|
public string BuildCallbackPath(string ssoUri = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return BuildSsoUrl(_oidcSigninPath, ssoUri);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string BuildSignedOutCallbackPath(string ssoUri = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return BuildSsoUrl(_oidcSignedOutPath, ssoUri);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-01 15:05:09 -04:00
|
|
|
|
public string BuildSaml2ModulePath(string ssoUri = null, string scheme = null)
|
2020-09-04 10:42:47 -04:00
|
|
|
|
{
|
2020-10-01 15:05:09 -04:00
|
|
|
|
return string.Concat(BuildSsoUrl(_saml2ModulePath, ssoUri),
|
|
|
|
|
|
string.IsNullOrWhiteSpace(scheme) ? string.Empty : $"/{scheme}");
|
2020-09-04 10:42:47 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-01 15:05:09 -04:00
|
|
|
|
public string BuildSaml2AcsUrl(string ssoUri = null, string scheme = null)
|
2020-09-08 13:04:26 -04:00
|
|
|
|
{
|
2020-10-01 15:05:09 -04:00
|
|
|
|
return string.Concat(BuildSaml2ModulePath(ssoUri, scheme), "/Acs");
|
2020-09-08 13:04:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-21 15:54:46 -05:00
|
|
|
|
public string BuildSaml2MetadataUrl(string ssoUri = null, string scheme = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return BuildSaml2ModulePath(ssoUri, scheme);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-10 12:00:12 -05:00
|
|
|
|
public IEnumerable<string> GetAdditionalScopes() => AdditionalScopes?
|
|
|
|
|
|
.Split(',')?
|
|
|
|
|
|
.Where(c => !string.IsNullOrWhiteSpace(c))?
|
|
|
|
|
|
.Select(c => c.Trim()) ??
|
|
|
|
|
|
Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAdditionalUserIdClaimTypes() => AdditionalUserIdClaimTypes?
|
|
|
|
|
|
.Split(',')?
|
|
|
|
|
|
.Where(c => !string.IsNullOrWhiteSpace(c))?
|
|
|
|
|
|
.Select(c => c.Trim()) ??
|
|
|
|
|
|
Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAdditionalEmailClaimTypes() => AdditionalEmailClaimTypes?
|
|
|
|
|
|
.Split(',')?
|
|
|
|
|
|
.Where(c => !string.IsNullOrWhiteSpace(c))?
|
|
|
|
|
|
.Select(c => c.Trim()) ??
|
|
|
|
|
|
Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAdditionalNameClaimTypes() => AdditionalNameClaimTypes?
|
|
|
|
|
|
.Split(',')?
|
|
|
|
|
|
.Where(c => !string.IsNullOrWhiteSpace(c))?
|
|
|
|
|
|
.Select(c => c.Trim()) ??
|
|
|
|
|
|
Array.Empty<string>();
|
|
|
|
|
|
|
2020-09-04 10:42:47 -04:00
|
|
|
|
private string BuildSsoUrl(string relativePath, string ssoUri)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ssoUri) ||
|
|
|
|
|
|
!Uri.IsWellFormedUriString(ssoUri, UriKind.Absolute))
|
|
|
|
|
|
{
|
|
|
|
|
|
return relativePath;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Uri.TryCreate(string.Concat(ssoUri.TrimEnd('/'), relativePath), UriKind.Absolute, out var newUri))
|
|
|
|
|
|
{
|
|
|
|
|
|
return newUri.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
return relativePath;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|