@@ -239,32 +239,30 @@ In this sample, a password is used to authenticate the service principal. The to
239
239
```
240
240
241
241
2 . Get a token:
242
- > [ !NOTE]
243
- > If you're using Azure Cloud Shell, the ` SecureClientSecret ` class isn't available.
244
-
245
- #### [ PowerShell] ( #tab/powershell )
246
242
``` powershell-interactive
247
- $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList "https://login.windows.net/<TENANT_ID>"
248
- $secureSecretObject = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.SecureClientSecret" -ArgumentList $SecureStringPassword
249
- $clientCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential" -ArgumentList $app.ApplicationId, $secureSecretObject
250
- $token=$authContext.AcquireTokenAsync("https://cognitiveservices.azure.com/", $clientCredential).Result
251
- $token
252
- ```
243
+ $tenantId = $context.Tenant.Id
244
+ $clientId = $app.ApplicationId
245
+ $clientSecret = "<YOUR_PASSWORD>"
246
+ $resourceUrl = "https://cognitiveservices.azure.com/"
253
247
254
- #### [ Azure Cloud Shell] ( #tab/azure-cloud-shell )
255
- ``` Azure Cloud Shell
256
- $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList "https://login.windows.net/<TENANT_ID>"
257
- $clientCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential" -ArgumentList $app.ApplicationId, <YOUR_PASSWORD>
258
- $token=$authContext.AcquireTokenAsync("https://cognitiveservices.azure.com/", $clientCredential).Result
259
- $token
260
- ```
248
+ $tokenEndpoint = "https://login.microsoftonline.com/$tenantId/oauth2/token"
249
+ $body = @{
250
+ grant_type = "client_credentials"
251
+ client_id = $clientId
252
+ client_secret = $clientSecret
253
+ resource = $resourceUrl
254
+ }
255
+
256
+ $responseToken = Invoke-RestMethod -Uri $tokenEndpoint -Method Post -Body $body
257
+ $accessToken = $responseToken.access_token
258
+ ```
261
259
262
260
---
263
261
264
262
3 . Call the Computer Vision API:
265
263
``` powershell-interactive
266
264
$url = $account.Endpoint+"vision/v1.0/models"
267
- $result = Invoke-RestMethod -Uri $url -Method Get -Headers @{"Authorization"=$token.CreateAuthorizationHeader() } -Verbose
265
+ $result = Invoke-RestMethod -Uri $url -Method Get -Headers @{"Authorization"="Bearer $accessToken" } -Verbose
268
266
$result | ConvertTo-Json
269
267
```
270
268
0 commit comments