Skip to content

Commit 32d02c8

Browse files
Merge pull request #206 from watson-developer-cloud/fix-iam
fix(iam): use access_token for iam
2 parents da248fe + 9118592 commit 32d02c8

File tree

4 files changed

+680
-1254
lines changed

4 files changed

+680
-1254
lines changed

app.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ require('./config/express')(app);
2727

2828
// Create the token manager
2929
let tokenManager;
30+
let instanceType;
3031
const serviceUrl = process.env.SPEECH_TO_TEXT_URL || 'https://stream.watsonplatform.net/speech-to-text/api';
3132

3233
if (process.env.SPEECH_TO_TEXT_IAM_APIKEY && process.env.SPEECH_TO_TEXT_IAM_APIKEY !== '') {
34+
instanceType = 'iam';
3335
tokenManager = new IamTokenManagerV1.IamTokenManagerV1({
3436
iamApikey: process.env.SPEECH_TO_TEXT_IAM_APIKEY || '<iam_apikey>',
3537
iamUrl: process.env.SPEECH_TO_TEXT_IAM_URL || 'https://iam.bluemix.net/identity/token',
3638
});
3739
} else {
40+
instanceType = 'cf';
3841
const speechService = new SpeechToTextV1({
3942
username: process.env.SPEECH_TO_TEXT_USERNAME || '<username>',
4043
password: process.env.SPEECH_TO_TEXT_PASSWORD || '<password>',
@@ -51,10 +54,19 @@ app.get('/api/credentials', (req, res, next) => {
5154
if (err) {
5255
next(err);
5356
} else {
54-
res.json({
55-
token,
56-
serviceUrl,
57-
});
57+
let credentials;
58+
if (instanceType === 'iam') {
59+
credentials = {
60+
accessToken: token,
61+
serviceUrl,
62+
};
63+
} else {
64+
credentials = {
65+
token,
66+
serviceUrl,
67+
};
68+
}
69+
res.json(credentials);
5870
}
5971
});
6072
});

0 commit comments

Comments
 (0)