mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Strapi Node): Add token credentials (#7048)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user