Description
Description of the new feature
The Get-AzAccessToken commandlet is awesome! Unfortunately I can't use it for my scenario because it's missing being able to set the "Scopes" in the authentication flow.
The feature request would be to enable passing scopes to the commandlet and could be done in two different ways:
Add -Scope as a parameter:
Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com" -Scope "Directory.readwrite.all"
Enable Resource URL to include scopes:
Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com//Directory.readwrite.all"
Scenario
I wanted to mention the scenario in which I want to use this feature: I am using the MicrosoftTeams PowerShell module (currently in preview). There is something supported by the API that's not yet supported by the module, so for 1 particular scenario, Adding tabs to an existing teams channel, I need to call the Rest API instead of a commandlet. The code looks like the following, but the Access Token part is the only bit of the code that doesn't work.
# First, see if the Lab Services Team app is already installed
$labServicesTeamsApp = Get-TeamsAppInstallation -TeamId $groupId -AppId $labServicesTeamsAppId
if (-not $labServicesTeamsApp) {
Add-TeamsAppInstallation -TeamId $groupId -AppId $labServicesTeamsAppId
}
# Config file doesn't currently have tab name, should we add it? Just assuming "General" tab for now
$tabDisplayName = "General"
$channel = Get-TeamChannel -GroupId $groupId | Where-Object {$_.DisplayName -ieq $tabDisplayName}
# -------------------------------------------------------------
# Code to add the app to the tab in the team
$apiUrl = "https://graph.microsoft.com/v1.0/teams/$groupId/channels/$($channel.Id)/tabs"
$apiBody = @"
{
"displayName": "Azure Lab Services",
"teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/$labServicesTeamsAppId",
"configuration": {
"entityId": "AzureLabs",
"contentUrl" : "https://labs.azure.com/subscriptions/$subscriptionId/resourcegroups/$resourceGroupName/providers/microsoft.labservices/labaccounts/$labAccountName/labs?host=Teams",
"removeUrl" : "",
"websiteUrl" : "https://labs.azure.com/subscriptions/$subscriptionId/resourcegroups/$resourceGroupName/providers/microsoft.labservices/labaccounts/$labAccountName/labs?referrer=Teams&tenantId=$tenantId&groupId=$groupId"
}
}
"@
# Need TeamsTab.ReadWrite.All scope for this token
# TODO: This line of code doesn't work - access token doesn't have the right scopes!
$accessToken = (Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com").Token
$tabdetails = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} `
-Uri $apiUrl `
-ContentType 'application/json' `
-Method POST `
-Body $apiBody -Verbose
$generaltabdetails = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} `
-Uri $apiUrl `
-ContentType 'application/json' `
-Method GET