Commit 9c73e7a6 authored by Carl Godkin's avatar Carl Godkin
Browse files

Added scope for Azure.

Added catch() for unhandled promise.
parent e912566c
......@@ -3,36 +3,42 @@ const axios = require('axios');
const authClient = require('./client-factory');
const OSDU_TARGET_PLATFORM = process.env.OSDU_TARGET_PLATFORM;
const AUTH_SCOPES = process.env.OSDU_AUTH_SCOPES.split(',').join(' ');
module.exports.authEntry = async (req, res) => {
const client = await authClient.clientFactory.getClient();
res.redirect(client.authorizationUrl());
res.redirect(client.authorizationUrl({scope: AUTH_SCOPES}));
};
module.exports.authCallback = async (req, res) => {
try {
const client = await authClient.clientFactory.getClient();
const params = client.callbackParams(req);
const data = await client.callback(authClient.CALLBACK_URL, params, {});
let bearer = '';
if (OSDU_TARGET_PLATFORM == 'azure')
bearer = 'Bearer ';
axios.defaults.headers.post['Authorization'] =
`${bearer}${data.access_token}`;
axios.defaults.headers.post['X-Id-Token'] = data.id_token;
// If interested in user info...
client.userinfo(data.access_token) // => Promise
.then(function (userinfo) {
console.log('userinfo %j', userinfo);
});
res.send (`<html><body><pre>${JSON.stringify(data, null, 4)}
</pre></body></html>`);
const client = await authClient.clientFactory.getClient();
const params = client.callbackParams(req);
const data = await client.callback(authClient.CALLBACK_URL, params, {});
let bearer = '';
if (OSDU_TARGET_PLATFORM == 'azure')
bearer = 'Bearer ';
axios.defaults.headers.post['Authorization'] =
`${bearer}${data.access_token}`;
axios.defaults.headers.post['X-Id-Token'] = data.id_token;
// If interested in user info...
client.userinfo(data.access_token) // => Promise
.then(function (userinfo) {
console.log('userinfo %j', userinfo);
}).catch (function (err) {
// Fetching userinfo in this way works on AWS but not on Azure.
// Note sure why. If you know, open an issue or submit PR to fix!
console.error ('Unable to get userinfo');
console.error (err);
});
res.send (`<html><body><pre>${JSON.stringify(data, null, 4)}
</pre></body></html>`);
}
catch (error) {
console.error (error);
console.error (error);
}
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment