Unable to aquire valid session id using an apex class
From this Article I was able to extract this method here:
First create a VisualForce page with the name: currentUserInfoCtrl
and then insert into it:
<apex:page >
Start_Of_Session_Id{!$Api.Session_ID}End_Of_Session_Id
</apex:page>
Then create a new Apex class that will reference the Apex Page
@AuraEnabled
public static String fetchUserSessionId(){
String sessionId = '';
// Refer to the Page
PageReference reportPage = Page.GetSessionIdVF;
// Get the content of the VF page
String vfContent = reportPage.getContent().toString();
System.debug('vfContent '+vfContent);
// Find the position of Start_Of_Session_Id and End_Of_Session_Id
Integer startP = vfContent.indexOf('Start_Of_Session_Id') + 'Start_Of_Session_Id'.length(),
endP = vfContent.indexOf('End_Of_Session_Id');
// Get the Session Id
sessionId = vfContent.substring(startP, endP);
System.debug('sessionId '+sessionId);
// Return Session Id
return sessionId;
}
I was able to get a valid session token using this method, and then attaching this apex class to my Lightning Component.