I am trying to integrate Salesforce with Jira using a Named Credential and oAuth 2.0. The Named Credential requires a Custom Auth. Provider which requires an
AuthProviderPluginClass. The authentication and authorization are working fine, and everything for the named credential appears to be stored as expected.
The hiccup here is that making requests with oAuth requires a
cloudId (issued by Jira) to be passed as part of the request URL. I can get the
cloudId for the authenticating user and use that to make additional requests while I'm still in the
AuthProviderPluginClass, but any attempt to persist the
cloudId has been met with failure. I can see the
cloudId and UserId in the debug logs, but no matter what I do I can't seem to save the
cloudId seemingly because the
AuthProviderPluginClass is 'swallowing' everything.
I have tried:
- Updating the User record using DML. I can see the
DML_OPERATIONline in the debug log, but the field on the User remains blank.
- Updating the User record using DML in a
@futuremethod. In this case I can see the
METHOD_ENTRYline in the debug log, but no
futureHandlerlog ever gets created and the field on the User remains blank.
- Adding a
cloudIdfield to the Custom Metadata driving the Auth. Provider, using Apex's
Metadataclass to deploy the
cloudIdwhen I retrieve it from Jira. This works when I run the code in the Execute Anonymous window, and once again I can see the
METHOD_ENTRYdebug line when I call the code from within the
AuthProviderPluginClass, but no deployment job gets created when the method is called this way.
I am aware that Jira supports basic authentication with UserName and Password, but since this is being deprecated and the integration I'm building is for an AppExchange package, I'd really like to get the oAuth flow working. Any tips on how to persist the
cloudId would be appreciated.