Create scopes fetcher

This commit is contained in:
Iván Ovejero 2022-04-20 15:59:49 +02:00
parent 94631f6fc2
commit d70a5da262

View file

@ -285,6 +285,33 @@ export class CredentialsHelper extends ICredentialsHelper {
return combineProperties;
}
/**
* Returns the scope of a credential type
*
* @param {string} type
* @returns {string[]}
* @memberof CredentialsHelper
*/
getScopes(type: string): string[] {
const scopeProperty = this.getCredentialsProperties(type).find(({ name }) => name === 'scope');
if (!scopeProperty?.default || typeof scopeProperty.default !== 'string') {
const errorMessage = `No \`scope\` property found for credential type: ${type}`;
Logger.error(errorMessage);
throw new Error(errorMessage);
}
const { default: scopeDefault } = scopeProperty;
if (/ /.test(scopeDefault)) return scopeDefault.split(' ');
if (/,/.test(scopeDefault)) return scopeDefault.split(',');
return [scopeDefault];
}
/**
* Returns the decrypted credential data with applied overwrites
*