1

When using a custom OAuth 2.0 provider as an extension of AuthProviderPluginClass for a Named Credential how does Salesforce check whether the current token is valid before attempting to request a new one? What's the flow?

In the docs for Connected Apps there are mentions of token introspection and other good stuff but I haven't been able to find anything on custom Auth. Providers or Named Credentials. Here is some reference material:

AuthProviderPluginClass

OAuth Tokens and Scopes

Named Credentials: Choose an Authentication Protocol

1 Answer 1

3

Salesforce closely follows the Oauth2.0 spec for a Named Credential OAuth2.0 flow.

When you save and start the Authentication flow, the page reference method initiate is called where your class has the URL to navigate to and complete the Oauth2.0 flow.

Once Authentication is successful the callback method handleCallback should have the logic to invoke the access token endpoint and get access and refresh tokens.

How does Salesforce check whether the current token is valid before attempting to request a new one?

This is based on the HTTP response code you get back making HTTP outnpund callout using the Named Credential in apex. If the HTTP response code returned is 401 then salesforce uses the refresh token to get the new access token. This is not documented well enough, however, there is some reference here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .