Skip to content

Commit

Permalink
fix(core): Fix OAuth credential creation via API (#5064)
Browse files Browse the repository at this point in the history
* fix(core): Fix OAuth credential creation via API

* Fix tests
  • Loading branch information
janober authored Jan 5, 2023
1 parent 62b2fc3 commit 93da026
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ export class CredentialsHelper extends ICredentialsHelper {
}

if (credentialTypeData.extends === undefined) {
// Manually add the special OAuth parameter which stores
// data like access- and refresh-token
if (['oAuth1Api', 'oAuth2Api'].includes(type)) {
return [
...credentialTypeData.properties,
{
displayName: 'oauthTokenData',
name: 'oauthTokenData',
type: 'json',
required: false,
default: {},
},
];
}

return credentialTypeData.properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ export function toJsonSchema(properties: INodeProperties[]): IDataObject {
// to later validate that only this properties are set in
// the credentials sent in the API call.
properties.forEach((property) => {
requiredFields.push(property.name);
if (property.required) {
requiredFields.push(property.name);
}
if (property.type === 'options') {
// if the property is type options,
// include all possible values in the enum property.
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/test/integration/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,21 @@ export function gitHubCredentialType(): ICredentialType {
name: 'server',
type: 'string',
default: 'https://api.github.com',
required: true,
description: 'The server to connect to. Only has to be set if Github Enterprise is used.',
},
{
displayName: 'User',
name: 'user',
type: 'string',
required: true,
default: '',
},
{
displayName: 'Access Token',
name: 'accessToken',
type: 'string',
required: true,
default: '',
},
],
Expand Down

0 comments on commit 93da026

Please sign in to comment.