mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Fix issue with OAuth2
This commit is contained in:
@@ -1194,6 +1194,15 @@ class App {
|
|||||||
|
|
||||||
let options = {};
|
let options = {};
|
||||||
|
|
||||||
|
const oAuth2Parameters = {
|
||||||
|
clientId: _.get(oauthCredentials, 'clientId') as string,
|
||||||
|
clientSecret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
||||||
|
accessTokenUri: _.get(oauthCredentials, 'accessTokenUrl', '') as string,
|
||||||
|
authorizationUri: _.get(oauthCredentials, 'authUrl', '') as string,
|
||||||
|
redirectUri: `${WebhookHelpers.getWebhookBaseUrl()}${this.restEndpoint}/oauth2-credential/callback`,
|
||||||
|
scopes: _.split(_.get(oauthCredentials, 'scope', 'openid,') as string, ',')
|
||||||
|
};
|
||||||
|
|
||||||
if (_.get(oauthCredentials, 'authentication', 'header') as string === 'body') {
|
if (_.get(oauthCredentials, 'authentication', 'header') as string === 'body') {
|
||||||
options = {
|
options = {
|
||||||
body: {
|
body: {
|
||||||
@@ -1201,16 +1210,10 @@ class App {
|
|||||||
client_secret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
client_secret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
delete oAuth2Parameters.clientSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oAuthObj = new clientOAuth2({
|
const oAuthObj = new clientOAuth2(oAuth2Parameters);
|
||||||
clientId: _.get(oauthCredentials, 'clientId') as string,
|
|
||||||
clientSecret: _.get(oauthCredentials, 'clientSecret', '') as string,
|
|
||||||
accessTokenUri: _.get(oauthCredentials, 'accessTokenUrl', '') as string,
|
|
||||||
authorizationUri: _.get(oauthCredentials, 'authUrl', '') as string,
|
|
||||||
redirectUri: `${WebhookHelpers.getWebhookBaseUrl()}${this.restEndpoint}/oauth2-credential/callback`,
|
|
||||||
scopes: _.split(_.get(oauthCredentials, 'scope', 'openid,') as string, ',')
|
|
||||||
});
|
|
||||||
|
|
||||||
const oauthToken = await oAuthObj.code.getToken(req.originalUrl, options);
|
const oauthToken = await oAuthObj.code.getToken(req.originalUrl, options);
|
||||||
|
|
||||||
|
|||||||
@@ -55,25 +55,13 @@ export class BitlyOAuth2Api implements ICredentialType {
|
|||||||
type: 'hidden' as NodePropertyTypes,
|
type: 'hidden' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'For some services additional query parameters have to be set which can be defined here.',
|
description: 'For some services additional query parameters have to be set which can be defined here.',
|
||||||
placeholder: 'access_type=offline',
|
placeholder: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Authentication',
|
displayName: 'Authentication',
|
||||||
name: 'authentication',
|
name: 'authentication',
|
||||||
type: 'options' as NodePropertyTypes,
|
type: 'hidden' as NodePropertyTypes,
|
||||||
options: [
|
default: 'body',
|
||||||
{
|
|
||||||
name: 'Body',
|
|
||||||
value: 'body',
|
|
||||||
description: 'Send credentials in body',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Header',
|
|
||||||
value: 'header',
|
|
||||||
description: 'Send credentials as Basic Auth header',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
default: 'header',
|
|
||||||
description: 'Resource to consume.',
|
description: 'Resource to consume.',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions |
|
|||||||
|
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} else {
|
} else {
|
||||||
return await this.helpers.requestOAuth2!.call(this, 'bitlyOAuth2Api', options);
|
//@ts-ignore
|
||||||
|
return await this.helpers.requestOAuth2!.call(this, 'bitlyOAuth2Api', options, 'Bearer');
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user