Skip to content

Commit

Permalink
Merge pull request #206 from watson-developer-cloud/fix-iam
Browse files Browse the repository at this point in the history
fix(iam): use access_token for iam
  • Loading branch information
germanattanasio authored Aug 3, 2018
2 parents da248fe + 9118592 commit 32d02c8
Show file tree
Hide file tree
Showing 4 changed files with 680 additions and 1,254 deletions.
20 changes: 16 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ require('./config/express')(app);

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

if (process.env.SPEECH_TO_TEXT_IAM_APIKEY && process.env.SPEECH_TO_TEXT_IAM_APIKEY !== '') {
instanceType = 'iam';
tokenManager = new IamTokenManagerV1.IamTokenManagerV1({
iamApikey: process.env.SPEECH_TO_TEXT_IAM_APIKEY || '<iam_apikey>',
iamUrl: process.env.SPEECH_TO_TEXT_IAM_URL || 'https://iam.bluemix.net/identity/token',
});
} else {
instanceType = 'cf';
const speechService = new SpeechToTextV1({
username: process.env.SPEECH_TO_TEXT_USERNAME || '<username>',
password: process.env.SPEECH_TO_TEXT_PASSWORD || '<password>',
Expand All @@ -51,10 +54,19 @@ app.get('/api/credentials', (req, res, next) => {
if (err) {
next(err);
} else {
res.json({
token,
serviceUrl,
});
let credentials;
if (instanceType === 'iam') {
credentials = {
accessToken: token,
serviceUrl,
};
} else {
credentials = {
token,
serviceUrl,
};
}
res.json(credentials);
}
});
});
Expand Down
Loading

0 comments on commit 32d02c8

Please sign in to comment.