1+ # Incremental scope consent.
2+ Connect-Graph - Scopes " Application.ReadWrite.All"
13
24# Create an application for use with DeviceCodeFlow
3- $app1 = new-mgApplication - displayName " DeviceCodeFlowApp" `
5+ $app1 = New-MgApplication - displayName " DeviceCodeFlowApp" `
46 - IsFallbackPublicClient `
5- - PublicClientRedirectUris " https://login.microsoftonline.com/common/oauth2/nativeclient"
7+ - PublicClient @ { `
8+ RedirectUris = " https://login.microsoftonline.com/common/oauth2/nativeclient" `
9+ }
610
711# Create an application for use with Native Client an interactive sign in
8- $app2 = new-mgApplication - displayName " NativeAppInteractiveFlowApp" `
12+ $app2 = New-MgApplication - displayName " NativeAppInteractiveFlowApp" `
913 - IsFallbackPublicClient `
10- - PublicClientRedirectUris " http://localhost"
14+ - PublicClient @ { `
15+ RedirectUris = " http://localhost" `
16+ }
1117
1218# Create an web app with implicit auth
13- $app3 = new-mgApplication - displayName " ImplicitWebApp" `
14- - ImplicitGrantSettingEnableAccessTokenIssuance `
15- - ImplicitGrantSettingEnableIdTokenIssuance `
16- - WebRedirectUris " https://localhost:3000/"
17-
19+ $app3 = New-MgApplication - displayName " ImplicitWebApp" `
20+ - Web @ { `
21+ RedirectUris = " https://localhost:3000/" ; `
22+ ImplicitGrantSettings = @ { `
23+ EnableAccessTokenIssuance = $true ; `
24+ EnableIdTokenIssuance = $true ; `
25+ } `
26+ }
27+
28+ # Create an application for use with Confidential Client flow using a certificate.
29+ # Get certificate from current user store.
30+ $CertificateThumbprint = " YOUR_THUMBPRINT"
31+ $Certificate = Get-ChildItem - Path " Cert:\CurrentUser\My\$CertificateThumbprint "
32+
33+ # Graph resource Id
34+ $GraphResourceId = " 00000003-0000-0000-c000-000000000000"
35+
36+ # Graph permissions constants
37+ $UserReadAll = @ { Id = " df021288-bdef-4463-88db-98f22de89214" ; Type = " Role" }
38+ $GroupReadAll = @ { Id = " 5b567255-7703-4780-807c-7be8301ae99b" ; Type = " Role" }
39+ $MailboxSettingsRead = @ { Id = " 40f97065-369a-49f4-947c-6a255697ae91" ; Type = " Role" }
40+ $MailSend = @ { Id = " b633e1c5-b582-4048-a93e-9f11b44c7e96" ; Type = " Role" }
41+
42+ # Create an application registration.
43+ $AppName = " ScriptedGraphPSApp"
44+ $app4 = New-MgApplication - " ClientCredentialApp" $AppName `
45+ - SignInAudience " AzureADMyOrg" `
46+ - RequiredResourceAccess @ { ResourceAppId = $graphResourceId ; ResourceAccess = $UserReadAll , $GroupReadAll , $MailboxSettingsRead , $MailSend } `
47+ - KeyCredentials @ (@ { Type = " AsymmetricX509Cert" ; Usage = " Verify" ; Key = $Certificate.RawData })
48+
49+ # Create corresponding service principal.
50+ New-MgServicePrincipal - AppId $appRegistration.AppId
0 commit comments