Getting the following error while trying to get a token from Azure Speech Service.
'https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken 401 (Access Denied)'.
Here is the way I'm requesting the token via JavaScript:
const res = await fetch('https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken', { method: 'POST', headers: { Authorization: 'Bearer ' + 'MY_SPEECH_SERVICES_SUBSCRIPTION_KEY'}});
const { authorizationToken } = await res.json();
webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({ authorizationToken, region });
My bot works fine if I get a token manually via Windows PowerShell though.
What could be possibly wrong?
Thx in advance
Asked
Active
Viewed 63 times
0

Amintas Lopes Neto
- 165
- 1
- 10
-
Are you using your Cognitive Services key or your bot secret to issue the token? Since you are trying to receive a token for the speech service, but it looks like you are using your bot secret for authentication. – Mick Mar 20 '20 at 12:57
-
Thanks Mick. Sorry for the typo in my problem statement. No I'm using the speech service key. – Amintas Lopes Neto Mar 20 '20 at 13:27
-
Are you getting `401` while you are getting sts token? – Md Farid Uddin Kiron Mar 20 '20 at 15:19
-
Yes. When I click on the bot mic the following message shows up: 'Failed to load resource: `the server responded with a status of 401 (Access Denied) brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken:1` I can see from the Google developer console (via F12 key press). I just found the following error is generated when I click on the dev console link: `{"error":{"code":"404","message": "Resource not found"}}` – Amintas Lopes Neto Mar 20 '20 at 16:00
1 Answers
0
Sharing a way to get the token via javascript. The 'data' variable will be storing the token. Thanks all for your support!
`<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
// Request parameters
};
$.ajax({
url: "https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","MY_SPEECH_SERVICES_SUBSCRIPTION_KEY");
},
type: "POST",
// Request body
data: "{body}",
})
.done(function(data) {
alert(data);
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>`

Amintas Lopes Neto
- 165
- 1
- 10