API access with client credentials (core functionality) (#16817)

* First stab

* Delivery API client credentials + a little refactor to ensure unique client IDs

* Introduce user type

* Support user type in the Management API

* Clean up TODOs

* Update API user last login date when issuing a token

* Better error reporting for mismatched user types

* Do not allow password change or reset for API users

* Update OpenApi.json

* Revert change

* Remove obsolete comment

* Make applicable classes abstract or sealed

* Review changes

* Add endpoint for retrieving all user client IDs
This commit is contained in:
Kenn Jacobsen
2024-07-29 14:34:11 +02:00
committed by GitHub
parent 0eef280a20
commit 68db079700
53 changed files with 1444 additions and 15 deletions

View File

@@ -39,6 +39,11 @@ public interface IUser : IMembershipUser, IRememberBeingDirty
/// </summary>
string? Avatar { get; set; }
/// <summary>
/// The type of user.
/// </summary>
UserType Type { get; set; }
void RemoveGroup(string group);
void ClearGroups();

View File

@@ -41,6 +41,7 @@ public class User : EntityBase, IUser, IProfile
private HashSet<IReadOnlyUserGroup> _userGroups;
private string _username;
private UserType _type;
/// <summary>
/// Constructor for creating a new/empty user
@@ -357,6 +358,13 @@ public class User : EntityBase, IUser, IProfile
set => SetPropertyValueAndDetectChanges(value, ref _language, nameof(Language));
}
[DataMember]
public UserType Type
{
get => _type;
set => SetPropertyValueAndDetectChanges(value, ref _type, nameof(Type));
}
/// <summary>
/// Gets the groups that user is part of
/// </summary>

View File

@@ -0,0 +1,7 @@
namespace Umbraco.Cms.Core.Models.Membership;
public enum UserType
{
Default = 0,
Api
}

View File

@@ -12,5 +12,7 @@ public class UserCreateModel
public string Name { get; set; } = string.Empty;
public UserType Type { get; set; }
public ISet<Guid> UserGroupKeys { get; set; } = new HashSet<Guid>();
}