project files added

This commit is contained in:
mhalfmann
2021-06-15 16:00:08 +02:00
parent e156e2f053
commit db46afa351
13928 changed files with 1569902 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
'use strict';
const url = require('url');
const qs = require('querystring');
const coreModule = require('./../core');
/**
* Authorization Code flow implementation
*/
module.exports = (config) => {
const core = coreModule(config);
const authorizeUrl = url.resolve(config.auth.authorizeHost, config.auth.authorizePath);
/**
* Redirect the user to the autorization page
* @param {String} params.redirectURI A string that represents the registered application URI
* where the user is redirected after authentication
* @param {String|Array<String>} params.scope A String or array of strings
* that represents the application privileges
* @param {String} params.state A String that represents an option opaque value used by the client
* to main the state between the request and the callback
* @return {String} the absolute authorization url
*/
function authorizeURL(params = {}) {
const baseParams = {
response_type: 'code',
[config.client.idParamName]: config.client.id,
};
if (Array.isArray(params.scope)) {
const scope = params.scope.join(',');
Object.assign(params, { scope });
}
const options = Object.assign({}, baseParams, params);
return `${authorizeUrl}?${qs.stringify(options)}`;
}
/**
* Returns the Access Token Object
* @param {String} params.code Authorization code (from previous step)
* @param {String} params.redirecURI A string that represents the callback uri
* @return {Promise}
*/
async function getToken(params) {
const options = Object.assign({}, params, {
grant_type: 'authorization_code',
});
return core.request(config.auth.tokenPath, options);
}
return {
authorizeURL,
getToken,
};
};
+28
View File
@@ -0,0 +1,28 @@
'use strict';
const coreModule = require('./../core');
/**
* Clients credentials flow implementation
*/
module.exports = (config) => {
const core = coreModule(config);
/**
* Returns the Access Token Object
* @param {Object} params
* @param {String} params.scope A string that represents the application privileges
* @return {Promise}
*/
async function getToken(params) {
const options = Object.assign({}, params, {
grant_type: 'client_credentials',
});
return core.request(config.auth.tokenPath, options);
}
return {
getToken,
};
};
+30
View File
@@ -0,0 +1,30 @@
'use strict';
const coreModule = require('./../core');
/**
* User Password flow implementation
*/
module.exports = (config) => {
const core = coreModule(config);
/**
* Returns the Access Token Object
* @param {Object} params
* @param {String} params.username A string that represents the registered username
* @param {String} params.password A string that represents the registered password
* @param {String} params.scope A string that represents the application privileges
* @return {Promise}
*/
async function getToken(params) {
const options = Object.assign({}, params, {
grant_type: 'password',
});
return core.request(config.auth.tokenPath, options);
}
return {
getToken,
};
};