minor bug fixes, optimizations, added test cases

This commit is contained in:
Sahil
2022-07-27 20:02:24 +05:30
parent 49131c5f5a
commit 320a5d7a20
2 changed files with 163 additions and 33 deletions

View File

@@ -1115,14 +1115,16 @@ module.exports = {
}
}
else if (securityDef.type === 'oauth2') {
let flowObj, currentFlowType;
helper = {
type: 'oauth2',
oauth2: []
};
let flowObj, currentFlowType, flowCollectionIdentifier;
if (securityDef.flows) {
if (_.isObject(securityDef.flows) && FLOW_TYPE[Object.keys(securityDef.flows)[0]]) {
/*
//===================[]========================\\
|| OAuth2 Flow Name || Key name in collection ||
|]===================[]========================[|
@@ -1133,36 +1135,24 @@ module.exports = {
\\===================[]========================//
Ref : https://swagger.io/docs/specification/authentication/oauth2/
In case of multiple flow types, the first one will be preferred
and passed on to the collection.
Other flow types in collection
Other flow types in collection which are not explicitly present in OA 3
• "authorization_code_with_pkce"
*/
if (securityDef.flows.hasOwnProperty('clientCredentials')) {
currentFlowType = FLOW_TYPE.clientCredentials;
flowObj = _.get(securityDef, 'flows.clientCredentials');
}
else if (securityDef.flows.hasOwnProperty('authorizationCode')) {
currentFlowType = FLOW_TYPE.authorizationCode;
flowObj = _.get(securityDef, 'flows.authorizationCode');
}
else if (securityDef.flows.hasOwnProperty('password')) {
currentFlowType = FLOW_TYPE.password;
flowObj = _.get(securityDef, 'flows.password');
}
else if (securityDef.flows.hasOwnProperty('implicit')) {
currentFlowType = FLOW_TYPE.implicit;
flowObj = _.get(securityDef, 'flows.implicit');
}
currentFlowType = FLOW_TYPE[Object.keys(securityDef.flows)[0]];
flowObj = _.get(securityDef, `flows.${Object.keys(securityDef.flows)[0]}`);
}
if (currentFlowType) { // Means the flow is of supported type
// Fields supported by all flows -> refreshUrl, scopes
if (!_.isEmpty(flowObj.scope)) {
if (!_.isEmpty(flowObj.scopes)) {
helper.oauth2.push({
key: 'scope',
value: _.isString(flowObj.scopes) ? flowObj.scopes : ''
value: Object.keys(flowObj.scopes).join(' ')
});
}
@@ -1177,25 +1167,28 @@ module.exports = {
// Fields supported by all flows except implicit -> tokenUrl
if (currentFlowType !== FLOW_TYPE.implicit) {
helper.oauth2.push({
key: 'accessTokenUrl',
value: _.isString(flowObj.tokenUrl) ? flowObj.tokenUrl : '<Access Token URL>'
});
if (!_.isEmpty(flowObj.tokenUrl)) {
helper.oauth2.push({
key: 'accessTokenUrl',
value: _.isString(flowObj.tokenUrl) ? flowObj.tokenUrl : '<Access Token URL>'
});
}
}
// Fields supported by all flows all except password, clientCredentials -> authorizationUrl
if (currentFlowType !== FLOW_TYPE.password && currentFlowType !== FLOW_TYPE.clientCredentials) {
helper.oauth2.push({
key: 'authUrl',
value: _.isString(flowObj.authUrl) ? flowObj.authUrl : '<Auth URL>'
});
if (!_.isEmpty(flowObj.authorizationUrl)) {
helper.oauth2.push({
key: 'authUrl',
value: _.isString(flowObj.authorizationUrl) ? flowObj.authorizationUrl : '<Auth URL>'
});
}
}
flowCollectionIdentifier = {
helper.oauth2.push({
key: 'grant_type',
value: currentFlowType
};
helper.oauth2.push(flowCollectionIdentifier);
});
}
}
else if (securityDef.type === 'apiKey') {