Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbod committed Mar 9, 2024
1 parent 9093bca commit 1bdc254
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions IssueVerifiableEmployee/Pages/EmployeeCredentials.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public EmployeeCredentialsModel(MicrosoftGraphDelegatedClient microsoftGraphDele
public async Task OnGetAsync()
{
var oid = User.Claims.FirstOrDefault(t => t.Type == Consts.OID_TYPE);

var employeeData = await _microsoftGraphDelegatedClient
.GetEmployee(oid!.Value);

Expand All @@ -51,7 +51,7 @@ public async Task OnGetAsync()
else
{
EmployeeMessage = $"You have no valid employee, Error: {employeeData.Error}";
if(employeeData.Error!.Contains("Preferred Language"))
if (employeeData.Error!.Contains("Preferred Language"))
{
PreferredLanguageMissing = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async override Task ValidatePrincipal(CookieValidatePrincipalContext cont
var tokenAcquisition = context.HttpContext.RequestServices
.GetRequiredService<ITokenAcquisition>();

string token = await tokenAcquisition.GetAccessTokenForUserAsync(scopes: _downstreamScopes,
string token = await tokenAcquisition.GetAccessTokenForUserAsync(scopes: _downstreamScopes,
user: context.Principal);
}
catch (MicrosoftIdentityWebChallengeUserException ex) when (AccountDoesNotExitInTokenCache(ex))
Expand All @@ -31,7 +31,7 @@ public async override Task ValidatePrincipal(CookieValidatePrincipalContext cont

private static bool AccountDoesNotExitInTokenCache(MicrosoftIdentityWebChallengeUserException ex)
{
return ex.InnerException is MsalUiRequiredException
return ex.InnerException is MsalUiRequiredException
&& (ex.InnerException as MsalUiRequiredException)!.ErrorCode == "user_null";
}
}
2 changes: 0 additions & 2 deletions IssueVerifiableEmployee/SecurityHeadersDefinitions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Microsoft.AspNetCore.Builder;

namespace IssuerVerifiableEmployee;

public static class SecurityHeadersDefinitions
Expand Down
2 changes: 1 addition & 1 deletion IssueVerifiableEmployee/Services/CacheData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Caching.Distributed;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Caching.Distributed;

namespace IssuerVerifiableEmployee.Services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ public MicrosoftGraphDelegatedClient(GraphServiceClient graphServiceClient)
return (null, "User MUST have a photo, upload in the Azure portal user basic profile, or using office");
}

var user = await _graphServiceClient.Users[oid]
var user = await _graphServiceClient.Users[oid]
.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = [
"id", "givenName", "surname", "jobTitle", "displayName",
"mail", "employeeId", "employeeType", "otherMails",
"mobilePhone", "accountEnabled", "photo", "preferredLanguage",
"userPrincipalName", "identities"];
requestConfiguration.QueryParameters.Select = [
"id",
"givenName",
"surname",
"jobTitle",
"displayName",
"mail",
"employeeId",
"employeeType",
"otherMails",
"mobilePhone",
"accountEnabled",
"photo",
"preferredLanguage",
"userPrincipalName",
"identities"];

requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
Expand Down Expand Up @@ -83,7 +94,7 @@ public MicrosoftGraphDelegatedClient(GraphServiceClient graphServiceClient)
Photo = photo,
AccountEnabled = user.AccountEnabled.GetValueOrDefault()
};

if (user.Mail != null)
{
employee.Mail = user.Mail;
Expand Down
10 changes: 5 additions & 5 deletions IssueVerifiableEmployee/Services/IssuerController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using IssuerVerifiableEmployee.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using System.Net;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using System.Net.Http.Headers;
using IssuerVerifiableEmployee.Services;
using Microsoft.AspNetCore.Authorization;
using System.Text.Json;
using Microsoft.Extensions.Caching.Distributed;
using System.Globalization;

namespace IssuerVerifiableEmployee;

Expand Down
4 changes: 2 additions & 2 deletions IssueVerifiableEmployee/Services/IssuerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<IssuanceRequestPayload> GetIssuanceRequestPayloadAsync(HttpReq

payload.Pin.Length = length;
payload.Pin.Value = newpin;

payload.CredentialsType = "VerifiedEmployee";

//get the manifest from the appsettings, this is the URL to the Verified Employee credential created in the azure portal.
Expand All @@ -57,7 +57,7 @@ public async Task<IssuanceRequestPayload> GetIssuanceRequestPayloadAsync(HttpReq
payload.Authority = _credentialSettings.IssuerAuthority;

var oid = request.HttpContext.User.Claims.FirstOrDefault(t => t.Type == Consts.OID_TYPE);

var (Employee, Error) = await _microsoftGraphDelegatedClient
.GetEmployee(oid!.Value);

Expand Down

0 comments on commit 1bdc254

Please sign in to comment.