-
Notifications
You must be signed in to change notification settings - Fork 192
Find-MgGraphPermission #809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a6f3fbb
525de57
525ba74
582f8de
40524de
fc94e03
3eeeaa9
e4770fa
ae89eec
c7315be
3c65b06
5e3a425
f5521f3
b7faf6f
d69cae3
ecf25b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,6 +226,8 @@ _pkginfo.txt | |
ClientBin/ | ||
~$* | ||
*~ | ||
.#* | ||
*# | ||
*.dbmdl | ||
*.dbproj.schemaview | ||
*.jfm | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ Connect-Graph | |
# Try to Get-User | ||
Get-MgUser | ||
|
||
# Search for delegated permissions related to sites | ||
Find-MgGraphPermission sites -PermissionType Delegated | ||
|
||
# Grant more permissions | ||
Connect-Graph -Scopes "User.Read","User.ReadWrite.All","Mail.ReadWrite",` | ||
"Directory.Read.All","Chat.ReadWrite", "People.Read", ` | ||
|
@@ -17,3 +20,6 @@ Connect-Graph -Scopes "User.Read","User.ReadWrite.All","Mail.ReadWrite",` | |
|
||
# Forget all access tokens | ||
Disconnect-Graph | ||
|
||
# Launch detailed permissions documentation | ||
Get-Help Find-MgGraphPermission -Online | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @msewaweru , this works because the .LINKS field in the comment help has exactly one entry, and it's the URI to the permissions docs. That means we can't provide references to other commands in .LINKS though -- hope that's ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maisarissi given the pointer by @adamedx it means we cannot use related links as we had intended to store Survey Links. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to sync with someone from the https://github.com/powershell/powershell or other experts on dcs + PowerShell project to confirm the behavior I observed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is such a limitation they should call Related Link instead of Related Links (plural) LOL |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ $app3 = New-MgApplication -displayName "ImplicitWebApp" ` | |
} | ||
|
||
# Create an registration for an ASP.NET Web App | ||
$scopeId_UserRead = Find-MgGraphPermission User.Read -ExactMatch -PermissionType Delegated | Select-Object -ExpandProperty Id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @peombwa you'll want to sign off on having the sample changed to use the new command. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good! This is a good example of how |
||
$app = New-MgApplication -displayName "AspNetWebApp" ` | ||
-Web @{ | ||
RedirectUris = "https://localhost:5001/signin-oidc"; ` | ||
|
@@ -36,7 +37,7 @@ $app = New-MgApplication -displayName "AspNetWebApp" ` | |
-RequiredResourceAccess @{ ResourceAppId = "00000003-0000-0000-c000-000000000000" | ||
ResourceAccess = @( | ||
@{ | ||
Id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d" | ||
Id = $scopeId_UserRead | ||
Type = "Scope" | ||
} | ||
) | ||
|
@@ -56,7 +57,7 @@ $createAppParams = @{ | |
ResourceAppId = "00000003-0000-0000-c000-000000000000" | ||
ResourceAccess = @( | ||
@{ | ||
Id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d" | ||
Id = $scopeId_UserRead | ||
Type = "Scope" | ||
} | ||
) | ||
|
@@ -76,18 +77,36 @@ $Certificate = Get-ChildItem -Path "Cert:\CurrentUser\My\$CertificateThumbprint" | |
# Graph resource Id | ||
$GraphResourceId = "00000003-0000-0000-c000-000000000000" | ||
|
||
# Graph permissions constants | ||
$UserReadAll = @{ Id = "df021288-bdef-4463-88db-98f22de89214"; Type = "Role" } | ||
$GroupReadAll = @{ Id = "5b567255-7703-4780-807c-7be8301ae99b"; Type = "Role" } | ||
$MailboxSettingsRead = @{ Id = "40f97065-369a-49f4-947c-6a255697ae91"; Type = "Role" } | ||
$MailSend = @{ Id = "b633e1c5-b582-4048-a93e-9f11b44c7e96"; Type = "Role" } | ||
# Show friendly Graph permission names given their unique identifiers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another big change to the sample @peombwa |
||
Find-MgGraphPermission | Where-Object Id -in @( | ||
'df021288-bdef-4463-88db-98f22de89214' | ||
'5b567255-7703-4780-807c-7be8301ae99b' | ||
'40f97065-369a-49f4-947c-6a255697ae91' | ||
'b633e1c5-b582-4048-a93e-9f11b44c7e96' | ||
) | ||
|
||
# Create an application registration. | ||
$requiredPermissions = 'Group.Read.All', 'Mail.Send', 'MailboxSettings.Read', 'User.Read.All' | | ||
Find-MgGraphPermission -ExactMatch -PermissionType Application | ||
|
||
$resourceAccess = foreach ( $permission in $requiredPermissions ) { | ||
@{ Id = $permission.Id; Type = 'Role' } | ||
} | ||
|
||
$AppName = "ScriptedGraphPSApp" | ||
$app4 = New-MgApplication -"ClientCredentialApp" $AppName ` | ||
-SignInAudience "AzureADMyOrg" ` | ||
-RequiredResourceAccess @{ ResourceAppId = $graphResourceId; ResourceAccess = $UserReadAll, $GroupReadAll, $MailboxSettingsRead, $MailSend } ` | ||
-RequiredResourceAccess @{ ResourceAppId = $graphResourceId; ResourceAccess = $resourceAccess } ` | ||
-KeyCredentials @(@{ Type = "AsymmetricX509Cert"; Usage = "Verify"; Key= $Certificate.RawData }) | ||
|
||
# Create corresponding service principal. | ||
New-MgServicePrincipal -AppId $app4.AppId | ||
|
||
# Show permissions assigned to the application in the organization | ||
# using friendly permission names instead of just the unique identifiers | ||
$servicePrincipal4 = Get-MgServicePrincipal -Filter "appId eq '$($app4.AppId)'" | ||
Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $servicePrincipal4.id | | ||
Select-Object appRoleId | | ||
Find-MgGraphPermission | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Load custom commands | ||
$customScriptCommandDirItem = Get-Item $PSScriptRoot -ErrorAction Ignore | ||
if ( $customScriptCommandDirItem ) { | ||
$customScriptCommandDir = join-path $customScriptCommandDirItem.FullName ../custom | ||
|
||
Get-ChildItem $customScriptCommandDir -Filter *.ps1 -ErrorAction Stop | ForEach-Object { | ||
. $_.FullName | ||
} | ||
} | ||
|
||
# Export custom script commands without removing the | ||
# binary cmdlets. Custom script commands are functions, | ||
# the cmdlets are.. cmdlets. We must explicitly specify | ||
# both functions and cmdlets at export; if only one of | ||
# these classes is specified, nothing of the other | ||
# class will be exported. | ||
Export-ModuleMember -Function * -Cmdlet * | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an FYI Exporting module members like this will suppress currently exported cmdlet aliases such as This will be fixed #816 when we merge the 2 PRs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adamedx, That's right. I'll merge the PR later today (to give others time to review it) then schedule everything for a 1.7.0 release. @FehintolaObafemi, thank you for the excellent contribution!! I'm quite sure our customers will find this command valuable for their scripts. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peombwa goal here is to show you can use the new command to find permissions, and also to get to the permissions reference help.