Skip to content

Commit 16856a3

Browse files
committed
Add Credential Endpoints
1 parent e5ecf6c commit 16856a3

File tree

82 files changed

+1717
-562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1717
-562
lines changed

samples/UAuthHub/CodeBeam.UltimateAuth.Sample.UAuthHub/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using CodeBeam.UltimateAuth.Sample.UAuthHub.Components;
1212
using CodeBeam.UltimateAuth.Security.Argon2;
1313
using CodeBeam.UltimateAuth.Server.Authentication;
14+
using CodeBeam.UltimateAuth.Server.Defaults;
1415
using CodeBeam.UltimateAuth.Server.Extensions;
1516
using CodeBeam.UltimateAuth.Sessions.InMemory;
1617
using CodeBeam.UltimateAuth.Tokens.InMemory;

samples/blazor-server/CodeBeam.UltimateAuth.Sample.BlazorServer/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using CodeBeam.UltimateAuth.Sample.BlazorServer.Components;
1010
using CodeBeam.UltimateAuth.Security.Argon2;
1111
using CodeBeam.UltimateAuth.Server.Authentication;
12+
using CodeBeam.UltimateAuth.Server.Defaults;
1213
using CodeBeam.UltimateAuth.Server.Extensions;
1314
using CodeBeam.UltimateAuth.Sessions.InMemory;
1415
using CodeBeam.UltimateAuth.Tokens.InMemory;
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
11
using CodeBeam.UltimateAuth.Core.Domain;
2+
using System.Collections;
23

34
namespace CodeBeam.UltimateAuth.Core.Contracts
45
{
56
public sealed class AccessContext
67
{
7-
public string? TenantId { get; init; }
8+
// Actor
89
public UserKey? ActorUserKey { get; init; }
9-
public string Action { get; init; } = default!;
10+
public string? ActorTenantId { get; init; }
11+
public bool IsAuthenticated { get; init; }
12+
public bool IsSystemActor { get; init; }
13+
14+
// Target
1015
public string? Resource { get; init; }
1116
public string? ResourceId { get; init; }
12-
public IReadOnlyDictionary<string, object>? Attributes { get; init; }
17+
public string? ResourceTenantId { get; init; }
18+
19+
public string Action { get; init; } = default!;
20+
public IReadOnlyDictionary<string, object> Attributes { get; init; } = EmptyAttributes.Instance;
21+
22+
public bool IsCrossTenant => ActorTenantId != null && ResourceTenantId != null && !string.Equals(ActorTenantId, ResourceTenantId, StringComparison.Ordinal);
23+
public bool IsSelfAction => ActorUserKey != null && ResourceId != null && string.Equals(ActorUserKey.Value, ResourceId, StringComparison.Ordinal);
24+
public bool HasActor => ActorUserKey != null;
25+
public bool HasTarget => ResourceId != null;
26+
}
27+
28+
internal sealed class EmptyAttributes : IReadOnlyDictionary<string, object>
29+
{
30+
public static readonly EmptyAttributes Instance = new();
31+
32+
private EmptyAttributes() { }
33+
34+
public IEnumerable<string> Keys => Array.Empty<string>();
35+
public IEnumerable<object> Values => Array.Empty<object>();
36+
public int Count => 0;
37+
public object this[string key] => throw new KeyNotFoundException();
38+
public bool ContainsKey(string key) => false;
39+
public bool TryGetValue(string key, out object value)
40+
{
41+
value = default!;
42+
return false;
43+
}
44+
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => Enumerable.Empty<KeyValuePair<string, object>>().GetEnumerator();
45+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
1346
}
1447
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using CodeBeam.UltimateAuth.Core.Contracts;
2+
3+
namespace CodeBeam.UltimateAuth.Server.Auth
4+
{
5+
internal sealed class DefaultAccessContextFactory : IAccessContextFactory
6+
{
7+
public AccessContext Create(AuthFlowContext authFlow, string action, string resource, string? resourceId = null, string? resourceTenantId = null, IReadOnlyDictionary<string, object>? attributes = null)
8+
{
9+
if (string.IsNullOrWhiteSpace(action))
10+
throw new ArgumentException("Action is required.", nameof(action));
11+
12+
if (string.IsNullOrWhiteSpace(resource))
13+
throw new ArgumentException("Resource is required.", nameof(resource));
14+
15+
return new AccessContext
16+
{
17+
ActorUserKey = authFlow.UserKey,
18+
ActorTenantId = authFlow.TenantId,
19+
IsAuthenticated = authFlow.IsAuthenticated,
20+
IsSystemActor = false,
21+
22+
Resource = resource,
23+
ResourceId = resourceId,
24+
ResourceTenantId = resourceTenantId ?? authFlow.TenantId,
25+
26+
Action = action,
27+
28+
Attributes = attributes ?? EmptyAttributes.Instance
29+
};
30+
}
31+
}
32+
}

src/CodeBeam.UltimateAuth.Server/Infrastructure/Auth/DefaultAuthContextFactory.cs renamed to src/CodeBeam.UltimateAuth.Server/Auth/Context/DefaultAuthContextFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using CodeBeam.UltimateAuth.Core.Abstractions;
22
using CodeBeam.UltimateAuth.Core.Contracts;
3-
using CodeBeam.UltimateAuth.Server.Auth;
43
using CodeBeam.UltimateAuth.Server.Extensions;
54

6-
namespace CodeBeam.UltimateAuth.Server.Infrastructure.Auth
5+
namespace CodeBeam.UltimateAuth.Server.Auth
76
{
87
internal sealed class DefaultAuthContextFactory : IAuthContextFactory
98
{

src/CodeBeam.UltimateAuth.Server/Auth/Context/DefaultAuthFlow.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ internal sealed class DefaultAuthFlow : IAuthFlow
99
private readonly IAuthFlowContextFactory _factory;
1010
private readonly DefaultAuthFlowContextAccessor _accessor;
1111

12-
public DefaultAuthFlow(
13-
IHttpContextAccessor http,
14-
IAuthFlowContextFactory factory,
15-
IAuthFlowContextAccessor accessor)
12+
public DefaultAuthFlow(IHttpContextAccessor http, IAuthFlowContextFactory factory, IAuthFlowContextAccessor accessor)
1613
{
1714
_http = http;
1815
_factory = factory;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using CodeBeam.UltimateAuth.Core.Contracts;
2+
3+
namespace CodeBeam.UltimateAuth.Server.Auth
4+
{
5+
public interface IAccessContextFactory
6+
{
7+
AccessContext Create(AuthFlowContext authFlow, string action, string resource, string? resourceId = null, string? resourceTenantId = null, IReadOnlyDictionary<string, object>? attributes = null);
8+
}
9+
}

src/CodeBeam.UltimateAuth.Server/Authentication/UAuthAuthenticationExtension.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Authentication;
1+
using CodeBeam.UltimateAuth.Server.Defaults;
2+
using Microsoft.AspNetCore.Authentication;
23

34
namespace CodeBeam.UltimateAuth.Server.Authentication;
45

src/CodeBeam.UltimateAuth.Server/Authentication/UAuthAuthenticationHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using CodeBeam.UltimateAuth.Core.Contracts;
33
using CodeBeam.UltimateAuth.Core.Domain;
44
using CodeBeam.UltimateAuth.Core.Extensions;
5+
using CodeBeam.UltimateAuth.Server.Defaults;
56
using CodeBeam.UltimateAuth.Server.Infrastructure;
67
using CodeBeam.UltimateAuth.Server.Services;
78
using Microsoft.AspNetCore.Authentication;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace CodeBeam.UltimateAuth.Server.Defaults
2+
{
3+
public static class UAuthActions
4+
{
5+
public static class Users
6+
{
7+
public const string Create = "users.create";
8+
public const string Delete = "users.delete";
9+
public const string ChangeStatus = "users.status.change";
10+
}
11+
12+
public static class UserProfiles
13+
{
14+
public const string GetSelf = "users.profile.get.self";
15+
public const string UpdateSelf = "users.profile.update.self";
16+
public const string GetAdmin = "users.profile.get.admin";
17+
public const string UpdateAdmin = "users.profile.update.admin";
18+
}
19+
20+
public static class UserIdentifiers
21+
{
22+
public const string Get = "users.identifiers.get";
23+
public const string Change = "users.identifiers.change";
24+
public const string Verify = "users.identifiers.verify";
25+
public const string Delete = "users.identifiers.delete";
26+
}
27+
28+
public static class Credentials
29+
{
30+
public const string List = "credentials.list";
31+
public const string Add = "credentials.add";
32+
public const string Change = "credentials.change";
33+
public const string Revoke = "credentials.revoke";
34+
public const string Activate = "credentials.activate";
35+
public const string Delete = "credentials.delete";
36+
}
37+
38+
}
39+
}

0 commit comments

Comments
 (0)