Skip to content

Commit 98e5441

Browse files
committed
updated scripts and readme
1 parent b70b363 commit 98e5441

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

AppCreationScripts/Configure.ps1

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,23 @@ Function UpdateTextFile([string] $configFilePath, [System.Collections.HashTable]
184184
Set-Content -Path $configFilePath -Value $lines -Force
185185
}
186186

187+
<#.Description
188+
This function takes a string as input and creates an instance of an Optional claim object
189+
#>
190+
Function CreateOptionalClaim([string] $name)
191+
{
192+
<#.Description
193+
This function creates a new Azure AD optional claims with default and provided values
194+
#>
195+
196+
$appClaim = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim
197+
$appClaim.AdditionalProperties = New-Object System.Collections.Generic.List[string]
198+
$appClaim.Source = $null
199+
$appClaim.Essential = $false
200+
$appClaim.Name = $name
201+
return $appClaim
202+
}
203+
187204
<#.Description
188205
Primary entry method to create and configure app registrations
189206
#>
@@ -237,6 +254,19 @@ Function ConfigureApplications
237254
New-MgApplicationOwnerByRef -ApplicationId $currentAppObjectId -BodyParameter = @{"@odata.id" = "htps://graph.microsoft.com/v1.0/directoryObjects/$user.ObjectId"}
238255
Write-Host "'$($user.UserPrincipalName)' added as an application owner to app '$($clientServicePrincipal.DisplayName)'"
239256
}
257+
258+
# Add Claims
259+
260+
$optionalClaims = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaims
261+
$optionalClaims.AccessToken = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
262+
$optionalClaims.IdToken = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
263+
$optionalClaims.Saml2Token = New-Object System.Collections.Generic.List[Microsoft.Graph.PowerShell.Models.MicrosoftGraphOptionalClaim]
264+
265+
# Add Optional Claims
266+
267+
$newClaim = CreateOptionalClaim -name "login_hint"
268+
$optionalClaims.IdToken += ($newClaim)
269+
Update-MgApplication -ApplicationId $currentAppObjectId -OptionalClaims $optionalClaims
240270
Write-Host "Done creating the client application (msal-node-desktop)"
241271

242272
# URL of the AAD application in the Azure portal
@@ -250,7 +280,7 @@ Function ConfigureApplications
250280
# Add Required Resources Access (from 'client' to 'Microsoft Graph')
251281
Write-Host "Getting access from 'client' to 'Microsoft Graph'"
252282
$requiredPermission = GetRequiredPermissions -applicationDisplayName "Microsoft Graph"`
253-
-requiredDelegatedPermissions "User.Read|Mail.Read"
283+
-requiredDelegatedPermissions "User.Read"
254284

255285
$requiredResourcesAccess.Add($requiredPermission)
256286
Write-Host "Added 'Microsoft Graph' to the RRA list."

AppCreationScripts/sample.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
"RequiredResourcesAccess": [
1919
{
2020
"Resource": "Microsoft Graph",
21-
"DelegatedPermissions": ["User.Read", "Mail.Read"]
21+
"DelegatedPermissions": ["User.Read"]
2222
}
23-
]
23+
],
24+
"OptionalClaims": {
25+
"IdTokenClaims": ["login_hint"]
26+
}
2427
}
2528
],
2629
"CodeConfiguration": [

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This sample demonstrates the following **MSAL Node** concepts:
3535
| `AppCreationScripts/` | Contains Powershell scripts for automating app registration. |
3636
| `App/authProvider.js` | Main authentication logic resides here. |
3737
| `App/main.js` | Application main process. |
38-
| `App/fetch.js` | Axios HTTP client for calling endpoints with a bearer token. |
38+
| `App/graph.js` | Instantiates Graph SDK client. |
3939
| `App/renderer.js` | Renderer processes and UI methods. |
4040
| `App/constants.js` | Example user accounts in JSON . |
4141
| `App/preload.js` | Give the Renderer process controlled access to some Node API.|
@@ -62,6 +62,15 @@ This sample demonstrates the following **MSAL Node** concepts:
6262
1. In the **Redirect URIs** section enter the following redirect URI `http://localhost`
6363
1. Select **Configure**.
6464

65+
##### Configure Optional Claims
66+
67+
1. Still on the same app registration, select the **Token configuration** blade to the left.
68+
1. Select **Add optional claim**:
69+
1. Select **optional claim type**, then choose **ID**.
70+
1. Select the optional claim **login_hint**.
71+
> An opaque, reliable login hint claim. This claim is the best value to use for the login_hint OAuth parameter in all flows to get SSO.See $[optional claims](https://docs.microsoft.com/azure/active-directory/develop/active-directory-optional-claims) for more details on this optional claim.
72+
1. Select **Add** to save your changes.
73+
6574
#### Step 2: Clone the repository
6675

6776
Clone this repository `git clone https://github.com/Azure-Samples/ms-identity-javascript-nodejs-desktop.git`

0 commit comments

Comments
 (0)