jarrad_obrien
jarrad_obrien

Reputation: 446

Can you get an access token for Azure with a username and password and without using a client_id via web request?

Scenario: I'm trying to get an access token using a web request as I cannot use Azure PowerShell. The situation I'm trying to replicate is Get-AzAccessToken, where I've authenticated using my username and password and I'm not supplying a client_id.

I can get an access token in PowerShell using the following:

$postParams = @{
  grant_type = 'password'
  client_id  = $ClientId
  username   = $Username
  password   = $Password
  scope      = 'https://graph.microsoft.com/.default'
}

Write-Host "Getting access token for app"
  
Invoke-RestMethod `
  -Uri https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token `
  -Method POST `
  -ContentType application/x-www-form-urlencoded `
  -Body $postParams

I can also get an access token by using the Azure PowerShell command Get-AzAccessToken.

Is it possible to get an access token without using a client_id? If not, is Get-AzAccessToken using a client_id?

Upvotes: 1

Views: 856

Answers (1)

juunas
juunas

Reputation: 58863

It is not possible without a client id. And yes, Azure PowerShell is using one. The best way to implement this is to register your own app and use its client id.

Upvotes: 0

Related Questions