NangoHQ / nango

A single API for all your integrations.
https://www.nango.dev
Other
4.7k stars 424 forks source link

Add support for Salesforce refresh token handling #327

Closed rguldener closed 1 year ago

rguldener commented 1 year ago

Salesforce OAuth flow has some uncommon handling of access token expiration, which makes it currently incompatible with Nango: Instead of providing an expires_at entry for the expiration time in the token response, it just returns an access token and a refresh token. To understand if the access token is expired you have two options:

Note that the expiration time of the access token can be set by the customer (along with an option to manually revoke it at any time).

These two methods are documented in more detail here: https://dev.to/xkit/when-do-salesforce-access-tokens-expire-1ih9#:~:text=Typical%20Token%20Expiration,any%20time%20with%20no%20warning.

Raw token response from Salesforce:

{
"access_token": "REDACTED",
    "refresh_token": "REDACTED",
    "signature": "VA0jxT+xl3HUdw1+Fz2f+47OD3AV490hgNhhkFYvPLE=",
    "scope": "refresh_token full",
    "id_token": "REDACTED-HUGE-PROBABLY-JWT",
    "instance_url": "https://nango-dev-ed.develop.my.salesforce.com",
    "id": "https://login.salesforce.com/id/REDACTED/REDACTED",
    "token_type": "Bearer",
    "issued_at": "1676372418560"
 }

Template for providers.yaml (to be inserted above salesloft):

salesforce:
    auth_mode: OAUTH2
    authorization_url: https://login.salesforce.com/services/oauth2/authorize
    token_url: https://login.salesforce.com/services/oauth2/token

DM me for credentials to test this with our Salesforce developer account.

bastienbeurier commented 1 year ago

Resolved by https://github.com/NangoHQ/nango/commit/b5abd94b41755ccb4f37d2684e49c568234920a9