mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
73 changed files with 1037 additions and 44 deletions
@ -0,0 +1,23 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Teams; |
|||
|
|||
public static class AuthDomainRecord |
|||
{ |
|||
public static string GetName(string domain) |
|||
{ |
|||
return $"_squidex.{domain}"; |
|||
} |
|||
|
|||
public static string GetValue(DomainId teamId) |
|||
{ |
|||
return $"squidex-team={teamId}"; |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Teams.Commands; |
|||
|
|||
public sealed class VerifyAuthDomain : TeamCommand |
|||
{ |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using DnsClient; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Teams; |
|||
|
|||
public sealed class DnsAuthDomainVerifier : IAuthDomainVerifier |
|||
{ |
|||
// Without the cache a record is found immediately after it has been added.
|
|||
private readonly LookupClient lookupClient = new LookupClient(new LookupClientOptions { UseCache = false, ThrowDnsErrors = false }); |
|||
|
|||
public async Task<bool> IsVerifiedAsync(string domain, DomainId teamId, |
|||
CancellationToken ct = default) |
|||
{ |
|||
var expected = AuthDomainRecord.GetValue(teamId); |
|||
|
|||
try |
|||
{ |
|||
var response = await lookupClient.QueryAsync(AuthDomainRecord.GetName(domain), QueryType.TXT, cancellationToken: ct); |
|||
|
|||
return response.Answers.TxtRecords().SelectMany(x => x.Text).Any(x => string.Equals(x.Trim(), expected, StringComparison.Ordinal)); |
|||
} |
|||
catch (DnsResponseException) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Teams; |
|||
|
|||
public interface IAuthDomainVerifier |
|||
{ |
|||
Task<bool> IsVerifiedAsync(string domain, DomainId teamId, |
|||
CancellationToken ct = default); |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace Squidex.Domain.Apps.Events.Teams; |
|||
|
|||
public sealed class TeamAuthDomainVerified : TeamEvent |
|||
{ |
|||
public string Domain { get; set; } |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Security.Claims; |
|||
|
|||
namespace Squidex.Config.Authentication; |
|||
|
|||
public static class VerifiedEmailExtensions |
|||
{ |
|||
// Not prefixed with 'urn:squidex:' so that it is never stored as a custom user claim.
|
|||
private const string ClaimType = "squidex_email_verified"; |
|||
|
|||
public static void SetEmailVerified(this ClaimsIdentity? identity, bool verified) |
|||
{ |
|||
if (identity == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
// Never trust a value that has been provided by the external identity provider.
|
|||
foreach (var claim in identity.FindAll(ClaimType).ToList()) |
|||
{ |
|||
identity.RemoveClaim(claim); |
|||
} |
|||
|
|||
if (verified) |
|||
{ |
|||
identity.AddClaim(new Claim(ClaimType, "true")); |
|||
} |
|||
} |
|||
|
|||
public static bool IsEmailVerified(this ClaimsPrincipal principal) |
|||
{ |
|||
return principal.HasClaim(ClaimType, "true"); |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
{ |
|||
sut: { |
|||
UniqueId: Guid_1, |
|||
Snapshot: { |
|||
Name: My Team, |
|||
Contributors: { |
|||
me: Owner |
|||
}, |
|||
AuthScheme: { |
|||
Domain: squidex.io, |
|||
DisplayName: Squidex, |
|||
ClientId: clientId, |
|||
ClientSecret: clientSecret, |
|||
Authority: https://identity.squidex.io |
|||
}, |
|||
IsAuthDomainVerified: true, |
|||
IsDeleted: false, |
|||
Id: Guid_1, |
|||
CreatedBy: subject:me, |
|||
LastModifiedBy: subject:me, |
|||
Version: 3, |
|||
UniqueId: Guid_1 |
|||
}, |
|||
Version: 3, |
|||
ObjectState: Created |
|||
}, |
|||
events: [ |
|||
{ |
|||
Headers: { |
|||
AggregateId: Guid_1, |
|||
EventId: Guid_2 |
|||
}, |
|||
Payload: { |
|||
Domain: squidex.io, |
|||
TeamId: Guid_1, |
|||
Actor: subject:me, |
|||
FromRule: false |
|||
} |
|||
} |
|||
] |
|||
} |
|||
Loading…
Reference in new issue