Skip to content

Commit 09ea76d

Browse files
author
Binon
committed
added new appsetting value - EnableMoodle
1 parent 972b40c commit 09ea76d

File tree

3 files changed

+397
-381
lines changed

3 files changed

+397
-381
lines changed

Auth/LearningHub.Nhs.Auth/Configuration/WebSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,10 @@ public class WebSettings
6161
/// Gets or sets a value indicating whether IsPasswordUpdate.
6262
/// </summary>
6363
public bool IsPasswordUpdate { get; set; }
64-
}
64+
65+
/// <summary>
66+
/// Gets or sets a value indicating whether gets or sets a value to Enable Moodle.
67+
/// </summary>
68+
public bool EnableMoodle { get; set; }
69+
}
6570
}

Auth/LearningHub.Nhs.Auth/UserServices/LearningHubProfileService.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using IdentityServer4.Extensions;
77
using IdentityServer4.Models;
88
using IdentityServer4.Services;
9+
using LearningHub.Nhs.Auth.Configuration;
910
using LearningHub.Nhs.Auth.Interfaces;
1011
using Microsoft.Extensions.Logging;
1112

@@ -14,6 +15,8 @@
1415
/// </summary>
1516
public class LearningHubProfileService : IProfileService
1617
{
18+
private readonly WebSettings webSettings;
19+
1720
/// <summary>
1821
/// Initializes a new instance of the <see cref="LearningHubProfileService"/> class.
1922
/// </summary>
@@ -26,11 +29,15 @@ public class LearningHubProfileService : IProfileService
2629
/// <param name="logger">
2730
/// The logger.
2831
/// </param>
29-
public LearningHubProfileService(IUserService userService, IMoodleApiService moodleApiService, ILogger<LearningHubProfileService> logger)
32+
/// <param name="webSettings">
33+
/// The webSettings.
34+
/// </param>
35+
public LearningHubProfileService(IUserService userService, IMoodleApiService moodleApiService, ILogger<LearningHubProfileService> logger, WebSettings webSettings)
3036
{
3137
this.UserService = userService;
3238
this.MoodleApiService = moodleApiService;
3339
this.Logger = logger;
40+
this.webSettings = webSettings;
3441
}
3542

3643
/// <summary>
@@ -62,8 +69,6 @@ public async Task GetProfileDataAsync(ProfileDataRequestContext context)
6269
if (context != null)
6370
{
6471
var user = await this.UserService.GetBasicUserByUserIdAsync(context.Subject.GetSubjectId());
65-
var moodleUser = await this.MoodleApiService.GetMoodleUserIdByUsernameAsync(user.Id);
66-
6772
var roleName = await this.UserService.GetUserRoleAsync(user.Id);
6873

6974
var claims = new List<Claim>
@@ -74,9 +79,14 @@ public async Task GetProfileDataAsync(ProfileDataRequestContext context)
7479
new Claim("family_name", user.LastName),
7580
new Claim("role", roleName),
7681
new Claim("elfh_userName", user.UserName),
77-
new Claim("preferred_username", moodleUser.ToString()),
7882
};
7983

84+
if (this.webSettings.EnableMoodle)
85+
{
86+
var moodleUser = await this.MoodleApiService.GetMoodleUserIdByUsernameAsync(user.Id);
87+
claims.Add(new Claim("preferred_username", moodleUser.ToString()));
88+
}
89+
8090
if (context.Subject.HasClaim("openAthensUser", "true"))
8191
{
8292
claims.Add(new Claim("openAthensUser", "true"));

0 commit comments

Comments
 (0)