Skip to content

Commit f875a66

Browse files
Update assigned access token API
1 parent 538c81c commit f875a66

File tree

5 files changed

+39
-51
lines changed

5 files changed

+39
-51
lines changed

src/Certify.Core/Management/Access/AccessControl.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,6 @@ public async Task<bool> AddAssignedRole(string contextUserId, AssignedRole r)
477477
return true;
478478
}
479479

480-
public async Task<bool> AddAssignedAccessToken(string contextUserId, AssignedAccessToken t)
481-
{
482-
if (!await IsPrincipleInRole(contextUserId, contextUserId, StandardRoles.Administrator.Id))
483-
{
484-
await AuditWarning("User {contextUserId} attempted to add an assigned access token without being in required role.", contextUserId);
485-
return false;
486-
}
487-
488-
await _store.Add(nameof(AssignedAccessToken), t);
489-
return true;
490-
}
491-
492480
public async Task<bool> AddResourceAction(string contextUserId, ResourceAction action)
493481
{
494482
if (!await IsPrincipleInRole(contextUserId, contextUserId, StandardRoles.Administrator.Id))
@@ -597,26 +585,26 @@ await GetSecurityPrincipleByUsername(contextUserId, passwordCheck.Username) :
597585
}
598586
}
599587

600-
public async Task<List<AccessToken>> GetAccessTokens(string contextUserId)
588+
public async Task<List<AssignedAccessToken>> GetAssignedAccessTokens(string contextUserId)
601589
{
602590
if (!await IsPrincipleInRole(contextUserId, contextUserId, StandardRoles.Administrator.Id))
603591
{
604-
await AuditWarning("User {contextUserId} attempted to list access tokens without being in required role.", contextUserId);
592+
await AuditWarning("User {contextUserId} attempted to list assigned access tokens without being in required role.", contextUserId);
605593
return [];
606594
}
607595

608-
return await _store.GetItems<AccessToken>(nameof(AccessToken));
596+
return await _store.GetItems<AssignedAccessToken>(nameof(AssignedAccessToken));
609597
}
610598

611-
public async Task<bool> AddAccessToken(string contextUserId, AccessToken a)
599+
public async Task<bool> AddAssignedAccessToken(string contextUserId, AssignedAccessToken a)
612600
{
613601
if (!await IsPrincipleInRole(contextUserId, contextUserId, StandardRoles.Administrator.Id))
614602
{
615-
await AuditWarning("User {contextUserId} attempted to add an access token without being in required role.", contextUserId);
603+
await AuditWarning("User {contextUserId} attempted to add an assigned access token without being in required role.", contextUserId);
616604
return false;
617605
}
618606

619-
await _store.Add(nameof(AccessToken), a);
607+
await _store.Add(nameof(AssignedAccessToken), a);
620608

621609
return true;
622610
}

src/Certify.Core/Management/Access/IAccessControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public interface IAccessControl
3131
Task<bool> AddAssignedRole(string contextUserId, AssignedRole assignedRole);
3232
Task<bool> AddResourceAction(string contextUserId, ResourceAction action);
3333

34-
Task<List<AccessToken>> GetAccessTokens(string contextUserId);
35-
Task<bool> AddAccessToken(string contextUserId, AccessToken token);
34+
Task<List<AssignedAccessToken>> GetAssignedAccessTokens(string contextUserId);
35+
Task<bool> AddAssignedAccessToken(string contextUserId, AssignedAccessToken token);
3636
Task<bool> IsInitialized();
3737
}
3838
}

src/Certify.Server/Certify.Server.Api.Public.Client/Certify.API.Public.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -429,22 +429,22 @@ public virtual async System.Threading.Tasks.Task<RoleStatus> GetSecurityPrincipl
429429
}
430430

431431
/// <summary>
432-
/// Get list of API access tokens [Generated]
432+
/// Get list of API assigned access tokens [Generated]
433433
/// </summary>
434434
/// <returns>OK</returns>
435435
/// <exception cref="ApiException">A server side error occurred.</exception>
436-
public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollection<AccessToken>> GetAccessTokensAsync()
436+
public virtual System.Threading.Tasks.Task<System.Collections.Generic.ICollection<AssignedAccessToken>> GetAssignedAccessTokensAsync()
437437
{
438-
return GetAccessTokensAsync(System.Threading.CancellationToken.None);
438+
return GetAssignedAccessTokensAsync(System.Threading.CancellationToken.None);
439439
}
440440

441441
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
442442
/// <summary>
443-
/// Get list of API access tokens [Generated]
443+
/// Get list of API assigned access tokens [Generated]
444444
/// </summary>
445445
/// <returns>OK</returns>
446446
/// <exception cref="ApiException">A server side error occurred.</exception>
447-
public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICollection<AccessToken>> GetAccessTokensAsync(System.Threading.CancellationToken cancellationToken)
447+
public virtual async System.Threading.Tasks.Task<System.Collections.Generic.ICollection<AssignedAccessToken>> GetAssignedAccessTokensAsync(System.Threading.CancellationToken cancellationToken)
448448
{
449449
var client_ = _httpClient;
450450
var disposeClient_ = false;
@@ -457,8 +457,8 @@ public virtual async System.Threading.Tasks.Task<RoleStatus> GetSecurityPrincipl
457457

458458
var urlBuilder_ = new System.Text.StringBuilder();
459459
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
460-
// Operation Path: "internal/v1/access/token"
461-
urlBuilder_.Append("internal/v1/access/token");
460+
// Operation Path: "internal/v1/access/assignedtoken"
461+
urlBuilder_.Append("internal/v1/access/assignedtoken");
462462

463463
PrepareRequest(client_, request_, urlBuilder_);
464464

@@ -485,7 +485,7 @@ public virtual async System.Threading.Tasks.Task<RoleStatus> GetSecurityPrincipl
485485
var status_ = (int)response_.StatusCode;
486486
if (status_ == 200)
487487
{
488-
var objectResponse_ = await ReadObjectResponseAsync<System.Collections.Generic.ICollection<AccessToken>>(response_, headers_, cancellationToken).ConfigureAwait(false);
488+
var objectResponse_ = await ReadObjectResponseAsync<System.Collections.Generic.ICollection<AssignedAccessToken>>(response_, headers_, cancellationToken).ConfigureAwait(false);
489489
if (objectResponse_.Object == null)
490490
{
491491
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
@@ -513,22 +513,22 @@ public virtual async System.Threading.Tasks.Task<RoleStatus> GetSecurityPrincipl
513513
}
514514

515515
/// <summary>
516-
/// Add new access token [Generated]
516+
/// Add new assigned access token [Generated]
517517
/// </summary>
518518
/// <returns>OK</returns>
519519
/// <exception cref="ApiException">A server side error occurred.</exception>
520-
public virtual System.Threading.Tasks.Task<ActionResult> AddAccessTokenAsync(AccessToken body)
520+
public virtual System.Threading.Tasks.Task<ActionResult> AddAssignedAccessTokenAsync(AssignedAccessToken body)
521521
{
522-
return AddAccessTokenAsync(body, System.Threading.CancellationToken.None);
522+
return AddAssignedAccessTokenAsync(body, System.Threading.CancellationToken.None);
523523
}
524524

525525
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
526526
/// <summary>
527-
/// Add new access token [Generated]
527+
/// Add new assigned access token [Generated]
528528
/// </summary>
529529
/// <returns>OK</returns>
530530
/// <exception cref="ApiException">A server side error occurred.</exception>
531-
public virtual async System.Threading.Tasks.Task<ActionResult> AddAccessTokenAsync(AccessToken body, System.Threading.CancellationToken cancellationToken)
531+
public virtual async System.Threading.Tasks.Task<ActionResult> AddAssignedAccessTokenAsync(AssignedAccessToken body, System.Threading.CancellationToken cancellationToken)
532532
{
533533
var client_ = _httpClient;
534534
var disposeClient_ = false;
@@ -545,8 +545,8 @@ public virtual async System.Threading.Tasks.Task<ActionResult> AddAccessTokenAsy
545545

546546
var urlBuilder_ = new System.Text.StringBuilder();
547547
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
548-
// Operation Path: "internal/v1/access/token"
549-
urlBuilder_.Append("internal/v1/access/token");
548+
// Operation Path: "internal/v1/access/assignedtoken"
549+
urlBuilder_.Append("internal/v1/access/assignedtoken");
550550

551551
PrepareRequest(client_, request_, urlBuilder_);
552552

src/Certify.Server/Certify.Server.Core/Certify.Server.Core/Controllers/AccessController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,19 @@ public async Task<bool> CheckSecurityPrincipleHasAccess(AccessCheck check)
117117
return await accessControl.IsAccessTokenAuthorised(GetContextUserId(), tokenCheck.Token, tokenCheck.Check);
118118
}
119119

120-
[HttpGet, Route("apitoken/list/")]
121-
public async Task<List<AccessToken>> GetAccessTokens()
120+
[HttpGet, Route("assignedtoken/list/")]
121+
public async Task<List<AssignedAccessToken>> GetAssignedAccessTokens()
122122
{
123123
var accessControl = await _certifyManager.GetCurrentAccessControl();
124124

125-
return await accessControl.GetAccessTokens(GetContextUserId());
125+
return await accessControl.GetAssignedAccessTokens(GetContextUserId());
126126
}
127127

128-
[HttpPost, Route("apitoken/")]
129-
public async Task<Models.Config.ActionResult> AddAccessToken([FromBody] AccessToken token)
128+
[HttpPost, Route("assignedtoken/")]
129+
public async Task<Models.Config.ActionResult> AddAAssignedccessToken([FromBody] AssignedAccessToken token)
130130
{
131131
var accessControl = await _certifyManager.GetCurrentAccessControl();
132-
var addResultOk = await accessControl.AddAccessToken(GetContextUserId(), token);
132+
var addResultOk = await accessControl.AddAssignedAccessToken(GetContextUserId(), token);
133133

134134
return new Models.Config.ActionResult
135135
{

src/Certify.SourceGenerators/ApiMethods.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ public static List<GeneratedAPI> GetApiDefinitions()
7373
ReturnType = "ICollection<Role>"
7474
},
7575
new() {
76-
OperationName = "GetAccessTokens",
76+
OperationName = "GetAssignedAccessTokens",
7777
OperationMethod = HttpGet,
78-
Comment = "Get list of API access tokens",
78+
Comment = "Get list of API assigned access tokens",
7979
PublicAPIController = "Access",
80-
PublicAPIRoute = "token",
81-
ServiceAPIRoute = "access/apitoken/list",
82-
ReturnType = "ICollection<Certify.Models.Hub.AccessToken>"
80+
PublicAPIRoute = "assignedtoken",
81+
ServiceAPIRoute = "access/assignedtoken/list",
82+
ReturnType = "ICollection<Certify.Models.Hub.AssignedAccessToken>"
8383
},
8484
new() {
85-
OperationName = "AddAccessToken",
85+
OperationName = "AddAssignedAccessToken",
8686
OperationMethod = HttpPost,
87-
Comment = "Add new access token",
87+
Comment = "Add new assigned access token",
8888
PublicAPIController = "Access",
89-
PublicAPIRoute = "token",
90-
ServiceAPIRoute = "access/apitoken",
89+
PublicAPIRoute = "assignedtoken",
90+
ServiceAPIRoute = "access/assignedtoken",
9191
ReturnType = "Models.Config.ActionResult",
92-
Params = new Dictionary<string, string>{{"token", "Certify.Models.Hub.AccessToken" } }
92+
Params = new Dictionary<string, string>{{"token", "Certify.Models.Hub.AssignedAccessToken" } }
9393
},
9494
new() {
9595

0 commit comments

Comments
 (0)