n8n-nodes-whoz
Version:
N8N community node for Whoz talent management platform
90 lines (89 loc) • 3.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WhozOAuth2Api = void 0;
class WhozOAuth2Api {
constructor() {
this.name = 'whozOAuth2Api';
this.displayName = 'Whoz OAuth2 API';
this.documentationUrl = 'https://developer.whoz.com/docs/whoz-api/2rdz8owfvfbkw-authentication';
this.properties = [
{
displayName: 'Environment',
name: 'environment',
type: 'options',
options: [
{
name: 'Production',
value: 'production',
},
{
name: 'Sandbox',
value: 'sandbox',
},
],
default: 'production',
description: 'Choose between production (www.whoz.com) and sandbox (sandbox.whoz.com) environment',
},
{
displayName: 'Grant Type',
name: 'grantType',
type: 'hidden',
default: 'clientCredentials',
},
{
displayName: 'Client ID',
name: 'clientId',
type: 'string',
required: true,
default: '',
description: 'Your Whoz API Client ID for OAuth authentication. Request API credentials from Whoz support if you don\'t have them yet.',
},
{
displayName: 'Client Secret',
name: 'clientSecret',
type: 'string',
typeOptions: {
password: true,
},
required: true,
default: '',
description: 'Your Whoz API Client Secret for OAuth authentication. Keep this value confidential.',
},
];
this.test = {
request: {
baseURL: '={{$credentials.environment === "sandbox" ? "https://sandbox.whoz.com" : "https://www.whoz.com"}}',
url: '/api/user/current',
method: 'GET',
headers: {
'Accept-Version': 'V15',
},
},
};
}
async authenticate(credentials, requestOptions) {
const baseUrl = credentials.environment === 'sandbox'
? 'https://sandbox.whoz.com'
: 'https://www.whoz.com';
const tokenUrl = `${baseUrl}/auth/realms/whoz/protocol/openid-connect/token`;
const tokenRequestOptions = {
method: 'POST',
url: tokenUrl,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
form: {
grant_type: 'client_credentials',
client_id: credentials.clientId,
client_secret: credentials.clientSecret,
},
};
requestOptions.headers = {
...requestOptions.headers,
'Accept-Version': 'V15',
'Content-Type': 'application/json',
};
return requestOptions;
}
}
exports.WhozOAuth2Api = WhozOAuth2Api;