Forum Discussion
Frank_Lehmann
Mar 03, 2025Copper Contributor
Error getting new token
Hi, i want to add a new member to a private channel. I follow the authentication flow as follows: a) starting with url https://login.microsoftonline.com/#tenantid#/oauth2/v2.0/authorize?client_id=...
RalfLueders
Mar 06, 2025Copper Contributor
Hallo Frank!
I'm using powershell to access Graph.
I assigned only application permissions to the Entra registered App (not delegated permissions!)
So when connecting to Graph, no scope is needed:
Connect Microsoft Graph
$body = @{
grant_type = "client_credentials"
scope = "https://graph.microsoft.com/.default"
client_id = $clientId
client_secret = $clientSecret
}
$response = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method Post -Body $body
$mgAccessToken = $response.access_token
$mgSecureAccessToken = ConvertTo-SecureString $mgaccessToken -AsPlainText -Force
$mg = Connect-MgGraph -AccessToken $mgSecureAccessToken