-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-SpeechAccessToken.ps1
27 lines (25 loc) · 1 KB
/
Get-SpeechAccessToken.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function Get-SpeechAccessToken() {
<#
.SYNOPSIS
Gets an Access Token for further API calls to the Speech to Text API
.DESCRIPTION
Gets an Access Token for further API calls to the Speech to Text API
.PARAMETER SubscriptionKey
The subscription key for the Cognitive Speech Service object
.PARAMETER RegionCode
The Azure Region where the Speech Service object resides, ex. "eastus"
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)] [Alias("Key")] [string] $SubscriptionKey,
[Parameter(Mandatory = $false)] [Alias("RegionCode")] [string] $Region = "eastus"
)
$FetchTokenHeader = @{
'Content-type' = 'application/x-www-form-urlencoded';
'Content-Length' = '0';
'Ocp-Apim-Subscription-Key' = $SubscriptionKey
}
$OAuthToken = Invoke-RestMethod -Method POST -Uri https://$Region.api.cognitive.microsoft.com/sts/v1.0/issueToken -Headers $FetchTokenHeader
# show the token received
Return $OAuthToken
}