I have created a custom Auth. Provider in Salesforce to reach out to an authorization server that isn't on the default list of Provider Types. I used https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/authproviderplugin.htm as a good starting point to extend the Auth.AuthProviderPluginClass. Once appropriately added to my org, it then became an option on the list of Provider Types. I was able to create an Auth. Provider using that new provider type and it works to initiate the OAuth2.0 flow. I am appropriately able to get the access token and refresh token from the authorization server.
As soon as I have the access token and refresh token in the
handleCallback function, I try to update my custom settings object with the access token and the refresh token:
MyCustom_API_Settings__c settings = MyCustom_API_Settings__c.getInstance(UserInfo.getUserId()); settings.Access_Token__c = resultWrapper.access_token; settings.Refresh_Token__c = resultWrapper.refresh_token; upsert settings; system.debug(settings.Access_Token__c);
I am able to see the token in the log. It appears to be successful and doesn't throw any errors...but no
MyCustom_API_Settings__c actually gets persisted for later use.
Is it possible to set Protected Managed Package Custom Settings from inside of a custom Auth Handler? If not, why not? If so, what should I do differently to get it to work?