feat(core): Replace client-oauth2 with an in-repo package (#6056)
Co-authored-by: Marcus <marcus@n8n.io>
This commit is contained in:
committed by
GitHub
parent
a4224649c5
commit
77ac953eaf
@@ -117,6 +117,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@n8n_io/license-sdk": "~2.4.0",
|
||||
"@n8n/client-oauth2": "workspace:*",
|
||||
"@oclif/command": "^1.8.16",
|
||||
"@oclif/core": "^1.16.4",
|
||||
"@oclif/errors": "^1.3.6",
|
||||
@@ -133,7 +134,6 @@
|
||||
"change-case": "^4.1.1",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.0",
|
||||
"client-oauth2": "^4.2.5",
|
||||
"compression": "^1.7.4",
|
||||
"connect-history-api-fallback": "^1.6.0",
|
||||
"convict": "^6.2.4",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import ClientOAuth2 from 'client-oauth2';
|
||||
import type { ClientOAuth2Options } from '@n8n/client-oauth2';
|
||||
import { ClientOAuth2 } from '@n8n/client-oauth2';
|
||||
import Csrf from 'csrf';
|
||||
import express from 'express';
|
||||
import get from 'lodash.get';
|
||||
@@ -119,7 +120,7 @@ oauth2CredentialController.get(
|
||||
};
|
||||
const stateEncodedStr = Buffer.from(JSON.stringify(state)).toString('base64');
|
||||
|
||||
const oAuthOptions: ClientOAuth2.Options = {
|
||||
const oAuthOptions: ClientOAuth2Options = {
|
||||
clientId: get(oauthCredentials, 'clientId') as string,
|
||||
clientSecret: get(oauthCredentials, 'clientSecret', '') as string,
|
||||
accessTokenUri: get(oauthCredentials, 'accessTokenUrl', '') as string,
|
||||
@@ -250,11 +251,11 @@ oauth2CredentialController.get(
|
||||
return renderCallbackError(res, errorMessage);
|
||||
}
|
||||
|
||||
let options = {};
|
||||
let options: Partial<ClientOAuth2Options> = {};
|
||||
|
||||
const oAuth2Parameters = {
|
||||
const oAuth2Parameters: ClientOAuth2Options = {
|
||||
clientId: get(oauthCredentials, 'clientId') as string,
|
||||
clientSecret: get(oauthCredentials, 'clientSecret', '') as string | undefined,
|
||||
clientSecret: get(oauthCredentials, 'clientSecret', '') as string,
|
||||
accessTokenUri: get(oauthCredentials, 'accessTokenUrl', '') as string,
|
||||
authorizationUri: get(oauthCredentials, 'authUrl', '') as string,
|
||||
redirectUri: `${getInstanceBaseUrl()}/${restEndpoint}/oauth2-credential/callback`,
|
||||
@@ -268,6 +269,7 @@ oauth2CredentialController.get(
|
||||
client_secret: get(oauthCredentials, 'clientSecret', '') as string,
|
||||
},
|
||||
};
|
||||
// @ts-ignore
|
||||
delete oAuth2Parameters.clientSecret;
|
||||
}
|
||||
|
||||
@@ -278,7 +280,8 @@ oauth2CredentialController.get(
|
||||
const queryParameters = req.originalUrl.split('?').splice(1, 1).join('');
|
||||
|
||||
const oauthToken = await oAuthObj.code.getToken(
|
||||
`${oAuth2Parameters.redirectUri}?${queryParameters}`,
|
||||
`${oAuth2Parameters.redirectUri as string}?${queryParameters}`,
|
||||
// @ts-ignore
|
||||
options,
|
||||
);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"include": ["src/**/*.ts", "test/**/*.ts", "src/sso/saml/saml-schema-metadata-2.0.xsd"],
|
||||
"references": [
|
||||
{ "path": "../workflow/tsconfig.build.json" },
|
||||
{ "path": "../core/tsconfig.build.json" }
|
||||
{ "path": "../core/tsconfig.build.json" },
|
||||
{ "path": "../@n8n/client-oauth2/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user