feat(Strapi Node): Add token credentials (#7048)

Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
Elias Meire
2023-08-31 12:46:28 +02:00
committed by GitHub
parent d72f79ffb3
commit c01bca562b
4 changed files with 138 additions and 8 deletions

View File

@@ -41,9 +41,39 @@ export class Strapi implements INodeType {
name: 'strapiApi',
required: true,
testedBy: 'strapiApiTest',
displayOptions: {
show: {
authentication: ['password'],
},
},
},
{
name: 'strapiTokenApi',
required: true,
displayOptions: {
show: {
authentication: ['token'],
},
},
},
],
properties: [
{
displayName: 'Authentication',
name: 'authentication',
type: 'options',
options: [
{
name: 'Username & Password',
value: 'password',
},
{
name: 'API Token',
value: 'token',
},
],
default: 'password',
},
{
displayName: 'Resource',
name: 'resource',
@@ -112,10 +142,18 @@ export class Strapi implements INodeType {
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
const { apiVersion } = await this.getCredentials('strapiApi');
const { jwt } = await getToken.call(this);
const authenticationMethod = this.getNodeParameter('authentication', 0);
let apiVersion: string;
if (authenticationMethod === 'password') {
const { jwt } = await getToken.call(this);
apiVersion = (await this.getCredentials('strapiApi')).apiVersion as string;
headers.Authorization = `Bearer ${jwt}`;
} else {
apiVersion = (await this.getCredentials('strapiTokenApi')).apiVersion as string;
}
headers.Authorization = `Bearer ${jwt}`;
for (let i = 0; i < length; i++) {
try {
if (resource === 'entry') {
@@ -213,6 +251,7 @@ export class Strapi implements INodeType {
{},
qs,
headers,
apiVersion,
);
} else {
qs['pagination[pageSize]'] = this.getNodeParameter('limit', i);
@@ -256,6 +295,7 @@ export class Strapi implements INodeType {
{},
qs,
headers,
apiVersion,
);
} else {
qs._limit = this.getNodeParameter('limit', i);