fix(core): Fix oauth2 callback and add integration tests (no-changelog) (#10272)
This commit is contained in:
committed by
GitHub
parent
785c82cfec
commit
efb71dd9ad
@@ -6,7 +6,6 @@ import type { ICredentialDataDecryptedObject, IWorkflowExecuteAdditionalData } f
|
||||
import { jsonParse, ApplicationError } from 'n8n-workflow';
|
||||
|
||||
import type { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { CredentialsRepository } from '@db/repositories/credentials.repository';
|
||||
import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository';
|
||||
import type { ICredentialsDb } from '@/Interfaces';
|
||||
@@ -71,8 +70,8 @@ export abstract class AbstractOAuthController {
|
||||
return credential;
|
||||
}
|
||||
|
||||
protected async getAdditionalData(user: User) {
|
||||
return await WorkflowExecuteAdditionalData.getBase(user.id);
|
||||
protected async getAdditionalData() {
|
||||
return await WorkflowExecuteAdditionalData.getBase();
|
||||
}
|
||||
|
||||
protected async getDecryptedData(
|
||||
@@ -119,7 +118,7 @@ export abstract class AbstractOAuthController {
|
||||
return await this.credentialsRepository.findOneBy({ id: credentialId });
|
||||
}
|
||||
|
||||
protected createCsrfState(credentialsId: string): [string, string] {
|
||||
createCsrfState(credentialsId: string): [string, string] {
|
||||
const token = new Csrf();
|
||||
const csrfSecret = token.secretSync();
|
||||
const state: CsrfStateParam = {
|
||||
|
||||
@@ -33,7 +33,7 @@ export class OAuth1CredentialController extends AbstractOAuthController {
|
||||
@Get('/auth')
|
||||
async getAuthUri(req: OAuthRequest.OAuth1Credential.Auth): Promise<string> {
|
||||
const credential = await this.getCredential(req);
|
||||
const additionalData = await this.getAdditionalData(req.user);
|
||||
const additionalData = await this.getAdditionalData();
|
||||
const decryptedDataOriginal = await this.getDecryptedData(credential, additionalData);
|
||||
const oauthCredentials = this.applyDefaultsAndOverwrites<OAuth1CredentialData>(
|
||||
credential,
|
||||
@@ -127,7 +127,7 @@ export class OAuth1CredentialController extends AbstractOAuthController {
|
||||
return this.renderCallbackError(res, errorMessage);
|
||||
}
|
||||
|
||||
const additionalData = await this.getAdditionalData(req.user);
|
||||
const additionalData = await this.getAdditionalData();
|
||||
const decryptedDataOriginal = await this.getDecryptedData(credential, additionalData);
|
||||
const oauthCredentials = this.applyDefaultsAndOverwrites<OAuth1CredentialData>(
|
||||
credential,
|
||||
|
||||
@@ -20,7 +20,7 @@ export class OAuth2CredentialController extends AbstractOAuthController {
|
||||
@Get('/auth')
|
||||
async getAuthUri(req: OAuthRequest.OAuth2Credential.Auth): Promise<string> {
|
||||
const credential = await this.getCredential(req);
|
||||
const additionalData = await this.getAdditionalData(req.user);
|
||||
const additionalData = await this.getAdditionalData();
|
||||
const decryptedDataOriginal = await this.getDecryptedData(credential, additionalData);
|
||||
|
||||
// At some point in the past we saved hidden scopes to credentials (but shouldn't)
|
||||
@@ -107,7 +107,7 @@ export class OAuth2CredentialController extends AbstractOAuthController {
|
||||
return this.renderCallbackError(res, errorMessage);
|
||||
}
|
||||
|
||||
const additionalData = await this.getAdditionalData(req.user);
|
||||
const additionalData = await this.getAdditionalData();
|
||||
const decryptedDataOriginal = await this.getDecryptedData(credential, additionalData);
|
||||
const oauthCredentials = this.applyDefaultsAndOverwrites<OAuth2CredentialData>(
|
||||
credential,
|
||||
|
||||
@@ -76,9 +76,7 @@ export type AuthlessRequest<
|
||||
ResponseBody = {},
|
||||
RequestBody = {},
|
||||
RequestQuery = {},
|
||||
> = APIRequest<RouteParams, ResponseBody, RequestBody, RequestQuery> & {
|
||||
user: never;
|
||||
};
|
||||
> = APIRequest<RouteParams, ResponseBody, RequestBody, RequestQuery>;
|
||||
|
||||
export type AuthenticatedRequest<
|
||||
RouteParams = {},
|
||||
|
||||
Reference in New Issue
Block a user