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
AmulyaAmulya 

Does JSON ID tokens get reset automatically?

We have a Webservice implementation done by some consultants which uses Rest API. We are trying to trace the code and understand. It looks like, we have used JSON Id tokens for authentication. Wanted to know if there is any expiry period for that and how to generate those tokens. We see that token value is same in Sandboxes as well as Production. Please find below the code snippet of JSON Parser.
public list<map<String,String>> parseJason(String result)
{
Map<String, String> amap=new Map<string, String>();
List<map<String,String>> mapList=new List<map<String,String>>();
if(result==''||result==null)
{ return mapList; }
Map<String, String> tempMap;
JSONParser parser = JSON.createParser(result);
boolean flag=false;
while (parser.nextToken() != null) { //System.debug('----');
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME))
{ String fieldName = parser.getText();
if(flag)
{
if(fieldName=='abstract')
{ ......}
} } }
NagendraNagendra (Salesforce Developers) 
Hi Amulya,

The "token" in that code refers to the parse tokens from the JSON class. These are not the same as JSON Web Tokens for authentication. This snippet definitely doesn't have anything explicit about authentication in it.

Regards,
Nagendra.
AmulyaAmulya

@Nagendra - Below the complete Apex class code just fyr. The token that salesforce sends(token will be encapsulated in URL) will be extracted and verified in the middleware(which has hardcoded token value in groovy script). Any idea how do we generate these parse tokens? 

public class AccountServiceControllerExtension2 {

    public final Account acct{get;Set;}
    public String siebelId{get;set;}
    public String requestBody{get;set;}
    public String requestResult{get;set;}
    
    public list<list<String>> mainList{get;set;}
    public String pageUrl{get;set;}
    
    public list<list<list<String>>> allList{get;set;}
    public list<list<String>> temp;
    public list<String> dataList1;
    public list<String> dataList2;
     
    public AccountServiceControllerExtension2(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
        pageUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/apex/ServiceRequest2?id='+acct.id;
        
        
        List<Account> siebelIdLs=[select Siebel_Row_ID__c from Account where Id=:acct.id limit 1];
        siebelId='';
        if(siebelIdLs.size()==1){
            if(siebelIdls.get(0).Siebel_Row_ID__c!=''&&siebelIdls.get(0).Siebel_Row_ID__c!=null){
                siebelId=siebelIdls.get(0).Siebel_Row_ID__c;

            }
        }
        
        String requestUrl='https://ASBintg.nat.olc.org/services/getServiceRequest';

        String result='';
        if(siebelId!=''){
            try{
                AccountHttpRequest ahr=new AccountHttpRequest();
                result=ahr.postCall(requestUrl,siebelId);
            }catch(Exception e){
                result='';
                requestResult='Can not get data from web service.';
            }
        }else{
            requestResult='No Siebel Row ID.';
        }
        
        List<map<String,String>> mapList=parseJason(result);   //get list data from json response
        if(mapList.size()>0){
            requestResult='valid';
            
            list<WebRequestMapListWrapper> wrapperList=new list<WebRequestMapListWrapper>();   
            
            for(Integer i=0;i<mapList.size();i++){
                WebRequestMapListWrapper wrapper1=new WebRequestMapListWrapper(mapList.get(i));
                wrapperList.add(wrapper1);
            }
            wrapperList.sort();
            
            mapList=new List<map<String,String>>();
            //reverse order
            for(Integer i = wrapperList.size()-1; i>=0;i--){
                mapList.add(wrapperList.get(i).dataMap);
            }
            
        }else{
            if(requestResult==''||requestResult==null)
            requestResult='No data for this account.';
        }
             
        allList=new List<list<list<String>>>();     //Top level list for all rows
        list<String> dataList1=new List<String>();
                       
        for(Integer i=0;i<mapList.size();i++){
            
            temp=new List<list<String>>();
            dataList1=new List<String>();          //Bottom level list for real data
            temp.add(dataList1);                  
            allList.add(temp); 
            
            if(mapList.get(i).get('abstract')==null) mapList.get(i).put('abstract','');
           //........same kind of statements
            
            
            dataList1.add(mapList.get(i).get('productShortName'));  //product
            dataList1.add(mapList.get(i).get('status'));  //status           
            dataList1.add('pageBlockTable'+String.valueOf(i)); //No.14              
    }}
       
    public list<map<String,String>> parseJason(String result){
        
        Map<String, String> amap=new Map<string, String>();
                
        List<map<String,String>> mapList=new List<map<String,String>>();
        if(result==''||result==null){
            return mapList;
        }
        
        Map<String, String> tempMap;
        
        JSONParser parser = JSON.createParser(result);
        boolean flag=false;
        
        while (parser.nextToken() != null) {
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){
                String fieldName = parser.getText();
                        
                if(flag){
                    if(fieldName=='abstract'){
                        tempMap = new Map<String, String>();
                        mapList.add(tempMap);
                        parser.nextToken();
                        tempMap.put('abstract',parser.getText());
                    }
                    //........same kind of statements
                }
                               
                if(fieldName=='serviceRequest'){
                    flag=true;     
                } } }
        
        return mapList;
}}}