• Franklin Ysaccis
  • NEWBIE
  • 5 Points
  • Member since 2019
  • Deloitte


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi all,

Due to the issue I have described here: https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=9060G0000005f11QAA, I have attempted to get a new OAuth access token programmatically using the usage notes for Auth.AuthToken.refreshAccessToken in the documentation here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Auth_AuthToken.htm#apex_class_Auth_AuthToken. For convenience, the usage example is:
 
String accessToken = Auth.AuthToken.getAccessToken('0SOD000000000De', 'Open ID connect');
Map<String, String> responseMap = Auth.AuthToken.refreshAccessToken('0SOD000000000De', 'Open ID connect', accessToken);
I am doing pretty much the same in exec anon:
 
AuthProvider pcs = [SELECT Id FROM AuthProvider WHERE DeveloperName = 'PCS'];
String accessToken = Auth.AuthToken.getAccessToken(pcs.Id, 'Open ID Connect');
Auth.AuthToken.refreshAccessToken(pcs.Id, 'Open ID Connect', accessToken);

The following exception is thrown in that code when I call refreshAccessToken: "System.InvalidParameterValueException: Argument cannot be null or empty".  Debugging "accessToken" reveals that it is null.  However, as far as I am concerned, it shouldn't be as I have passed the correct auth provider id and provider type.

This is my Auth. Provider config:

Auth Provider
This is the named credential that uses it:

Named Credential

I've tried with both Named Prinicipal and Per User.  Can anyone assist me with getting this to work?

Many thanks,

Miles

I am attempting to programmatically archive Attachments in Salesforce over to Google Drive. Google Drive API requires OAuth and I am having a little bit of trouble setting it up.

I was trying to avoid building and parsing HTTP Requests/Responses in order to get through the Authorization Flow but my attempts have failed.

First, I configured an API Project via the Google API ConsoleUser-added image

Second, I created an AuthProvider in Salesforce.
User-added image

At this point, I would expect the following code sample to grab an Access Token for me:
system.debug(Auth.AuthToken.getAccessToken('0SO4B000000CacK', 'Open ID Connect'));
However, I receive a null value.

For good measure, duplicated everything for a Google Auth Provider, instead of  Open Id Connect with the same result. I also set up an external data source (which does authenticate and sync) to make sure I had a token.

Has anyone been able to successfully use AuthToken methods when connecting to Google APIs?
Is there anything that I missed along the way?