+ Start a Discussion
Sami ShakithSami Shakith 

Not getting session Id in identity provider (Salesforce to salesforce integration using canvas)

Hi,

I am trying to develop S2S integration using canvas application. For that i followed http://www.jitendrazaa.com/blog/salesforce/salesforce-to-salesforce-integration-using-canvas/ In that he asked to develop a VF(in service provider) which will be called in identity provider. 

VF code is as below
<apex:page showHeader="false">
    
    <script type="text/javascript" src="{!URLFOR($Resource.CanvasSDK,'SalesforceCanvasJavascriptSDK-master/js/canvas-all.js')}" />
    
    <script type="text/javascript">
        
        var sid="{!GETSESSIONID()}".substr(1,30) +'...';
    
    	function refreshSR(){
        	Sfdc.canvas.client.refreshSignedRequest(function(data){
            	
                if(data.status == 200){
                	var signedRequest = data.payload.response;
                    var part = signedRequest.split('.')[1];
                    var obj = JSON.parse(Sfdc.canvas.decode(part));
                    updateDisplay(obj) ;
                } 
            }); 
        }
    
    function updateDisplay(obj){
    	setValue('spSessionId', sid);
        setValue('ipOAuth', obj.client.oauthToken.substr(1,30)+'...');
        setValue('ipUser', obj.context.user.fullName);
        setValue('ipOrg', obj.context.organization.name);
        setValue('ipRefresh', obj.client.refreshToken.substr(1,30)+'...');
    }
    
    function setValue(eleId,val)
    {
       	var domEl = document.getElementById(eleId);
        if(domEl){
        	domEl.innerHTML = val;    
        }
    }
    
    Sfdc.canvas.onReady(function(){
    	refreshSR();
    });
         
    </script>
          
        <b> <u> Service Provider Org </u></b>  
        I am Canvas App from Salesforce Domain <b> Jitendra.zaa5@gmail.com </b>      
        User : {!$User.FirstName} {!$User.LastName} 
        Org : {!$Organization.Name}
        Session Id : <span id="spSessionId"></span>    

<hr />
 
        <b> <u> Identity Provider Org  - Current Org </u> </b>
        User : <span id="ipUser"></span>
         Org : <span id="ipOrg"></span>
         OAUth Token : <span id="ipOAuth"></span>
        Refresh Token : <span id="ipRefresh"></span>
     
</apex:page>
My VF page showing without the session id and informations of identity provider as belowUser-added image
How to get those values. I Need some one help to resolve it. 

Thanks.
JitendraJitendra
Hi Sami, It sems issue with Connected App setting, Can you please check your developer console of page by pressing "Ctrl+Shift+J" if you are using googe chrome. If possible please paste screen shot.
Sami ShakithSami Shakith
Thanks for your reply Jitendra.

I have sorted out this by another code.

Below code working fine in my dev account.
 
<apex:page showHeader="false">
<script type='text/javascript' src='/canvas/sdk/js/canvas-all.js'/>
<script>
    function refreshSR() {
        Sfdc.canvas.client.refreshSignedRequest(function(data) {
            if (data.status === 200) {
                var signedRequest = data.payload.response;
                var part = signedRequest.split('.')[1];
                var obj = JSON.parse(Sfdc.canvas.decode(part));
                updateDisplay(obj);
            }
        });
     }
    function updateDisplay(obj) {
        var oauth = document.getElementById('oauth');
        oauth.innerHTML = obj.client.oauthToken;
        var user = document.getElementById('user');
        user.innerHTML = obj.context.user.fullName;
        var org = document.getElementById('org');
        org.innerHTML = obj.context.organization.name;
    }
</script>
<p/>
Service Provider User: {!$User.FirstName} {!$User.LastName}<br/>
Service Provider Org: {!$Organization.Name}<br/>
<p/>
Identity Provider User: <span id="user"></span><br/>
Identity Provider Org: <span id="org"></span><br/>
Identity Provider OAuth Token: <span id="oauth"></span><br/>
<p/>
<input id="refresh" type="button" value="Refresh SR" onclick="refreshSR();"/>
</apex:page>