diff --git a/src/Ombi/.vscode/settings.json b/src/Ombi/.vscode/settings.json index 497cd5996..f7b75c335 100644 --- a/src/Ombi/.vscode/settings.json +++ b/src/Ombi/.vscode/settings.json @@ -15,6 +15,7 @@ "discover", "request-limits", "notifications", - "settings" + "settings", + "user-management" ] } diff --git a/src/Ombi/ClientApp/src/app/services/identity.service.ts b/src/Ombi/ClientApp/src/app/services/identity.service.ts index 1b0f6d8c4..e10df1337 100644 --- a/src/Ombi/ClientApp/src/app/services/identity.service.ts +++ b/src/Ombi/ClientApp/src/app/services/identity.service.ts @@ -24,6 +24,10 @@ export class IdentityService extends ServiceHelpers { return this.http.get(`${this.url}accesstoken`, {headers: this.headers}); } + public getUserAccessToken(userId: string): Observable { + return this.http.get(`${this.url}accesstoken/${userId}`, {headers: this.headers}); + } + public getUserById(id: string): Observable { return this.http.get(`${this.url}User/${id}`, {headers: this.headers}); } diff --git a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts index 038de9b64..eac863282 100644 --- a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts +++ b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts @@ -69,7 +69,7 @@ export class UserManagementUserComponent implements OnInit { this.radarrService.getRootFoldersFromSettings().subscribe(x => this.radarrRootFolders = x); this.settingsService.getCustomization().subscribe(x => this.customization = x); - this.identityService.getAccessToken().subscribe(x => this.accessToken = x); + this.identityService.getUserAccessToken(this.userId).subscribe(x => this.accessToken = x); if(!this.edit) { this.user = { diff --git a/src/Ombi/Controllers/V1/IdentityController.cs b/src/Ombi/Controllers/V1/IdentityController.cs index a186f6694..fded4cacc 100644 --- a/src/Ombi/Controllers/V1/IdentityController.cs +++ b/src/Ombi/Controllers/V1/IdentityController.cs @@ -947,6 +947,30 @@ namespace Ombi.Controllers.V1 return user.UserAccessToken; } + [HttpGet("accesstoken/{userId}")] + [PowerUser] + [ApiExplorerSettings(IgnoreApi = true)] + public async Task GetUserAccessToken(string userId) + { + var user = await UserManager.Users.FirstOrDefaultAsync(x => x.Id == userId); + if (user == null) + { + return Guid.Empty.ToString("N"); + } + if (user.UserAccessToken.IsNullOrEmpty()) + { + // Let's create an access token for this user + user.UserAccessToken = Guid.NewGuid().ToString("N"); + var result = await UserManager.UpdateAsync(user); + if (!result.Succeeded) + { + LogErrors(result); + return Guid.Empty.ToString("N"); + } + } + return user.UserAccessToken; + } + [HttpGet("notificationpreferences")] public async Task> GetUserPreferences() {