function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rohit Soni 35Rohit Soni 35 

Issue with fetching access token for current user

Hey Folks , wanted to check if anyone has used this api - Auth.AuthToken.getAccessToken(...) , basically I am trying to retrieve the Access Token for the current user , I am finding it has cached in Access token for some other user and returns that one , instead of the token corresponding to the current user
Can anyone please help here?, also is there a way to get hold of the ID_token for the current user?
SwethaSwetha (Salesforce Developers) 
HI Rohit,
Is there a code snippet you can provide so I can replicate the issue to suggest better? Thanks

Checked related:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Auth_AuthToken.htm

https://salesforce.stackexchange.com/questions/321677/how-to-access-oauth-token-stored-in-namedcredential-using-apex-for-use-in-other/321680
 
Rohit Soni 35Rohit Soni 35
Hi Swetha, Here is the code : String accessToken = Auth.AuthToken.getAccessToken(, 'Open ID connect'); I am doing this inside a registration handler , when federating a user from an external system , it should return the access token for the user getting federated , but instead it returns the Access token corresponding to some other user. Thanks Rohit