Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 956a377

Browse files
committed
bump msal
1 parent 9d048c3 commit 956a377

File tree

9 files changed

+89
-117
lines changed

9 files changed

+89
-117
lines changed

AppCreationScripts/Configure.ps1

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,28 +289,30 @@ Function ConfigureApplications
289289
# rename the user_impersonation scope if it exists to match the readme steps or add a new scope
290290
$scopes = New-Object System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.OAuth2Permission]
291291

292-
if ($scopes.Count -ge 0)
292+
# delete default scope i.e. User_impersonation
293+
$scope = $serviceAadApplication.Oauth2Permissions | Where-Object { $_.Value -eq "User_impersonation" }
294+
if($scope -ne $null)
293295
{
294-
# add all existing scopes first
295-
$serviceAadApplication.Oauth2Permissions | foreach-object { $scopes.Add($_) }
296-
297-
$scope = $serviceAadApplication.Oauth2Permissions | Where-Object { $_.Value -eq "User_impersonation" }
296+
# disable the scope
297+
$scope.IsEnabled = $false
298+
$scopes.Add($scope)
299+
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -Oauth2Permissions $scopes
300+
301+
# clear the scope
302+
$scopes.Clear()
303+
Set-AzureADApplication -ObjectId $serviceAadApplication.ObjectId -Oauth2Permissions $scopes
304+
}
298305

299-
if ($scope -ne $null)
300-
{
301-
$scope.Value = "access_as_user"
302-
}
303-
else
304-
{
305-
# Add scope
306-
$scope = CreateScope -value "access_as_user" `
306+
if ($scopes.Count -ge 0)
307+
{
308+
$scope = CreateScope -value access_as_user `
307309
-userConsentDisplayName "Access ProfileAPI" `
308310
-userConsentDescription "Allow the application to access ProfileAPI on your behalf." `
309311
-adminConsentDisplayName "Access ProfileAPI" `
310312
-adminConsentDescription "Allows the app to have the same access to information in the directory on behalf of the signed-in user."
311313

312-
$scopes.Add($scope)
313-
}
314+
$scopes.Add($scope)
315+
314316
}
315317

316318
# add/update scopes
@@ -396,13 +398,13 @@ Function ConfigureApplications
396398
# Update config file for 'service'
397399
$configFile = $pwd.Path + "\..\ProfileAPI\appsettings.json"
398400
Write-Host "Updating the sample code ($configFile)"
399-
$dictionary = @{ "Domain" = $tenantName;"ClientId" = $serviceAadApplication.AppId;"ClientSecret" = $serviceAppKey };
401+
$dictionary = @{ "Domain" = $tenantName;"ClientId" = $serviceAadApplication.AppId;"ClientSecret" = $serviceAppKey;"TenantId" = $tenantId };
400402
UpdateTextFile -configFilePath $configFile -dictionary $dictionary
401403

402404
# Update config file for 'client'
403405
$configFile = $pwd.Path + "\..\ProfileSPA\src\utils\authConfig.js"
404406
Write-Host "Updating the sample code ($configFile)"
405-
$dictionary = @{ "Enter the Client Id (aka 'Application ID')" = $clientAadApplication.AppId;"Enter the API scopes as declared in the app registration 'Expose an Api' blade in the form of 'api://{client_id}/.default'" = ("api://"+$serviceAadApplication.AppId+"/access_as_user") };
407+
$dictionary = @{ "Enter_the_Application_Id_Here" = $clientAadApplication.AppId;"Enter_the_Tenant_Info_Here" = $tenantId;"Enter_the_Application_Id_of_Service_Here" = $serviceAadApplication.AppId };
406408
ReplaceInTextFile -configFilePath $configFile -dictionary $dictionary
407409
Write-Host ""
408410
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
@@ -416,7 +418,13 @@ Function ConfigureApplications
416418
Write-Host " - Navigate to the Manifest page and set the value 'replyUrlsWithType' as 'Spa'." -ForegroundColor Red
417419

418420
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
419-
421+
if($isOpenSSL -eq 'Y')
422+
{
423+
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
424+
Write-Host "You have generated certificate using OpenSSL so follow below steps: "
425+
Write-Host "Install the certificate on your system from current folder."
426+
Write-Host -ForegroundColor Green "------------------------------------------------------------------------------------------------"
427+
}
420428
Add-Content -Value "</tbody></table></body></html>" -Path createdApps.html
421429
}
422430

AppCreationScripts/sample.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
{
7272
"key": "ClientSecret",
7373
"value": "service.AppKey"
74+
},
75+
{
76+
"key": "TenantId",
77+
"value": "$tenantId"
7478
}
7579
]
7680
},
@@ -81,12 +85,16 @@
8185
"SettingFile": "\\..\\ProfileSPA\\src\\utils\\authConfig.js",
8286
"Mappings": [
8387
{
84-
"key": "Enter the Client Id (aka 'Application ID')",
88+
"key": "Enter_the_Application_Id_Here",
8589
"value": "client.AppId"
8690
},
8791
{
88-
"key": "Enter the API scopes as declared in the app registration 'Expose an Api' blade in the form of 'api://{client_id}/.default'",
89-
"value": "service.Scope"
92+
"key": "Enter_the_Tenant_Info_Here",
93+
"value": "$tenantId"
94+
},
95+
{
96+
"key": "Enter_the_Application_Id_of_Service_Here",
97+
"value": "service.AppId"
9098
}
9199
]
92100
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 08/04/2021
4+
5+
* Updated MSAL.js to 2.13.1 and M.I.W to 1.8.2
6+
* Sample now targets work and school accounts, instead of personal Microsoft accounts.
7+
38
## 20/02/2021
49

510
* Updated MSAL.js to 2.11 and M.I.W to 1.6

ProfileAPI/Controllers/ProfileController.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,7 @@ public async Task<ActionResult<ProfileItem>> PostProfileItem(ProfileItem profile
7373
{
7474
User profile = await _graphServiceClient.Me.Request().GetAsync();
7575

76-
string graphID;
77-
78-
// OID is represented in id_token as a 32 digit number, while in MS Graph API, the
79-
// preceding 0s are sometimes omitted. The following operation adds the omitted 0s back.
80-
81-
if (profile.Id.Length < 32)
82-
{
83-
int x = 32 - profile.Id.Length;
84-
graphID = new string('0', x) + profile.Id;
85-
}
86-
else
87-
{
88-
graphID = profile.Id;
89-
}
90-
91-
profileItem.Id = graphID;
76+
profileItem.Id = profile.Id;
9277
profileItem.UserPrincipalName = profile.UserPrincipalName;
9378
profileItem.GivenName = profile.GivenName;
9479
profileItem.Surname = profile.Surname;

ProfileAPI/appsettings.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44
"ClientId": "Enter the application ID (clientId) of the 'ProfileAPI' application copied from the Azure portal",
55
"ClientSecret": "Enter the client secret of the 'ProfileAPI' application copied from the Azure portal",
66
"Instance": "https://login.microsoftonline.com/",
7-
"TenantId": "consumers"
7+
"TenantId": "Enter the ID of your Azure AD tenant"
88
},
99
"DownstreamAPI": {
10-
/*
11-
'Scopes' contains space separated scopes of the web API you want to call. This can be:
12-
- a scope for a V2 application (for instance api:b3682cc7-8b30-4bd2-aaba-080c6bf0fd31/access_as_user)
13-
- a scope corresponding to a V1 application (for instance <App ID URI>/.default, where <App ID URI> is the
14-
App ID URI of a legacy v1 Web application
15-
Applications are registered in the https:portal.azure.com portal.
16-
*/
1710
"Scopes": "User.Read",
1811
"BaseUrl": "https://graph.microsoft.com/v1.0/"
1912
},

ProfileSPA/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"author": "derisen",
55
"dependencies": {
6-
"@azure/msal-browser": "^2.13.0",
6+
"@azure/msal-browser": "^2.13.1",
77
"bootstrap": "^4.5.0",
88
"react": "^16.14.0",
99
"react-bootstrap": "^1.2.2",

ProfileSPA/src/utils/authConfig.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// visit https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/configuration.md
33
export const msalConfig = {
44
auth: {
5-
clientId: "Enter the Client Id (aka 'Application ID')",
6-
authority: "https://login.microsoftonline.com/consumers",
5+
clientId: "Enter_the_Application_Id_Here",
6+
authority: "https://login.microsoftonline.com/Enter_the_Tenant_Info_Here",
77
redirectUri: "http://localhost:3000"
88
},
99
cache: {
@@ -15,7 +15,7 @@ export const msalConfig = {
1515
// Coordinates and required scopes for your web API
1616
export const apiConfig = {
1717
resourceUri: "https://localhost:44351/api/profile",
18-
resourceScopes: ["Enter the API scopes as declared in the app registration 'Expose an Api' blade in the form of 'api://{client_id}/.default'"]
18+
resourceScopes: ["api://Enter_the_Application_Id_of_Service_Here/.default'"]
1919
}
2020

2121
/**

0 commit comments

Comments
 (0)