mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Add sandbox option to Salesforce OAuth2 credentials (#1979)
* ⚡ Add environment dropdown to OAuth2 creds * ⚡ Add sandbox URL to OAuth2 call * ⏪ Revert options change * ⚡ Set OAuth2 URLs with expressions * ⚡ Extract instance URL from credentials
This commit is contained in:
parent
e40f0e00a8
commit
c5a1bc007f
|
@ -11,19 +11,35 @@ export class SalesforceOAuth2Api implements ICredentialType {
|
|||
displayName = 'Salesforce OAuth2 API';
|
||||
documentationUrl = 'salesforce';
|
||||
properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Environment Type',
|
||||
name: 'environment',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Production',
|
||||
value: 'production',
|
||||
},
|
||||
{
|
||||
name: 'Sandbox',
|
||||
value: 'sandbox',
|
||||
},
|
||||
],
|
||||
default: 'production',
|
||||
},
|
||||
{
|
||||
displayName: 'Authorization URL',
|
||||
name: 'authUrl',
|
||||
type: 'hidden',
|
||||
default: 'https://login.salesforce.com/services/oauth2/authorize',
|
||||
required: true,
|
||||
default: '={{ $self["environment"] === "sandbox" ? "https://test.salesforce.com/services/oauth2/authorize" : "https://login.salesforce.com/services/oauth2/authorize" }}',
|
||||
},
|
||||
{
|
||||
displayName: 'Access Token URL',
|
||||
name: 'accessTokenUrl',
|
||||
type: 'string',
|
||||
default: 'https://yourcompany.salesforce.com/services/oauth2/token',
|
||||
type: 'hidden',
|
||||
required: true,
|
||||
default: '={{ $self["environment"] === "sandbox" ? "https://test.salesforce.com/services/oauth2/token" : "https://login.salesforce.com/services/oauth2/token" }}',
|
||||
},
|
||||
{
|
||||
displayName: 'Scope',
|
||||
|
|
|
@ -40,9 +40,8 @@ export async function salesforceApiRequest(this: IExecuteFunctions | IExecuteSin
|
|||
} else {
|
||||
// https://help.salesforce.com/articleView?id=remoteaccess_oauth_web_server_flow.htm&type=5
|
||||
const credentialsType = 'salesforceOAuth2Api';
|
||||
const credentials = this.getCredentials(credentialsType);
|
||||
const subdomain = ((credentials!.accessTokenUrl as string).match(/https:\/\/(.+).salesforce\.com/) || [])[1];
|
||||
const options = getOptions.call(this, method, (uri || endpoint), body, qs, `https://${subdomain}.salesforce.com`);
|
||||
const credentials = this.getCredentials(credentialsType) as { oauthTokenData: { instance_url: string } };
|
||||
const options = getOptions.call(this, method, (uri || endpoint), body, qs, credentials.oauthTokenData.instance_url);
|
||||
Logger.debug(`Authentication for "Salesforce" node is using "OAuth2". Invoking URI ${options.uri}`);
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, credentialsType, options);
|
||||
|
|
Loading…
Reference in a new issue