n8n/packages/nodes-base/credentials/OAuth2Api.credentials.ts
agobrech fc7261aca6
feat(core): Add PKCE for OAuth2 (#6324)
* Remove authorization header when empty

* Import pkce

* Add OAuth2 with new grant type to Twitter

* Add pkce logic auto assign authorization code if pkce not defined

* Add pkce to ui and interfaces

* Fix scopes for Oauth2 twitter

* Deubg + pass it through header

* Add debug console, add airtable cred

* Remove all console.logs, make PKCE in th body only when it exists

* Remove invalid character ~

* Remove more console.logs

* remove body inside query

* Remove useless grantype check

* Hide oauth2 twitter waiting for overhaul

* Remove redundant header removal

* Remove more console.logs

* Add comment for code verifier

* Remove uneeded scopes

* Restore client id in callback

* Revert "Add OAuth2 with new grant type to Twitter"

This reverts commit 1c3b331aa1.

* Remove oauth2 from twitter

* Remove properties linked to oauth2

* Fix lodash imports

* remove redundant check

* remove redundant codeVerifier

* patch pkce-challenge to avoid generating `code_verifier` with `~`

* store `codeVerifier` on the DB like `csrfSecret`

* remove unrelated changes

---------

Co-authored-by: Marcus <marcus@n8n.io>
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2023-06-21 10:54:32 +02:00

109 lines
2 KiB
TypeScript

import type { ICredentialType, INodeProperties } from 'n8n-workflow';
export class OAuth2Api implements ICredentialType {
name = 'oAuth2Api';
displayName = 'OAuth2 API';
documentationUrl = 'httpRequest';
genericAuth = true;
properties: INodeProperties[] = [
{
displayName: 'Grant Type',
name: 'grantType',
type: 'options',
options: [
{
name: 'Authorization Code',
value: 'authorizationCode',
},
{
name: 'Client Credentials',
value: 'clientCredentials',
},
{
name: 'PKCE',
value: 'pkce',
},
],
default: 'authorizationCode',
},
{
displayName: 'Authorization URL',
name: 'authUrl',
type: 'string',
displayOptions: {
show: {
grantType: ['authorizationCode', 'pkce'],
},
},
default: '',
required: true,
},
{
displayName: 'Access Token URL',
name: 'accessTokenUrl',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Client ID',
name: 'clientId',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Client Secret',
name: 'clientSecret',
type: 'string',
typeOptions: {
password: true,
},
default: '',
required: true,
},
{
displayName: 'Scope',
name: 'scope',
type: 'string',
default: '',
},
{
displayName: 'Auth URI Query Parameters',
name: 'authQueryParameters',
type: 'string',
displayOptions: {
show: {
grantType: ['authorizationCode', 'pkce'],
},
},
default: '',
description:
'For some services additional query parameters have to be set which can be defined here',
placeholder: 'access_type=offline',
},
{
displayName: 'Authentication',
name: 'authentication',
type: 'options',
options: [
{
name: 'Body',
value: 'body',
description: 'Send credentials in body',
},
{
name: 'Header',
value: 'header',
description: 'Send credentials as Basic Auth header',
},
],
default: 'header',
},
];
}