Last active
August 29, 2015 14:24
-
-
Save lkatney/46ec9f128db362d167d0 to your computer and use it in GitHub Desktop.
Accessing canvas signed request while using VF page as Canvas app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <apex:page showHeader="false" sidebar="false" controller="CanvasVoteController"> | |
| <apex:form > | |
| <apex:vote objectId="{!ideaId}"></apex:vote> | |
| </apex:form> | |
| </apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public with sharing class CanvasVoteController { | |
| public String ideaId {get;set;} | |
| public CanvasVoteController() { | |
| System.debug(ApexPages.CurrentPage().getParameters()); | |
| String signed_request = ApexPages.CurrentPage().getParameters().get('signed_request'); | |
| system.debug(signed_request); | |
| if(String.isNotBlank(signed_request)){ | |
| String jsonData = EncodingUtil.base64Decode(signed_request.replace('.',':').split(':')[1]).toString(); | |
| system.debug(jsonData); | |
| SignedRequestWrapper requestObj = (SignedRequestWrapper) System.JSON.deserialize(jsonData,SignedRequestWrapper.class); | |
| system.debug(requestObj); | |
| cls_parameters params = requestObj.context.environment.parameters; | |
| ideaId = params.Id; | |
| system.debug(ideaId); | |
| } | |
| } | |
| public class SignedRequestWrapper{ | |
| public String algorithm; //HMACSHA256 | |
| public Integer issuedAt; //1402819425 | |
| public String userId; //00590000000tQBwAAM | |
| public cls_client client; | |
| public cls_context context; | |
| } | |
| class cls_client { | |
| public cls_refreshToken refreshToken; | |
| public String instanceId; //lk_main:Idea_Vote:0D59000001lbhaX | |
| public String targetOrigin; //https://ap1.salesforce.com | |
| public String instanceUrl; //https://ap1.salesforce.com | |
| public String oauthToken; //00D90000000azEO!ARYAQICDEbmnSC2XNqFFJd4F2lg6CM3u0DF2XHlQgQaUHnfOPSvDCUWeP3.T1PfDtjCt7zJssbofHuDF4w_L2aUCXwO9VnXo | |
| } | |
| class cls_refreshToken { | |
| } | |
| class cls_context { | |
| public cls_user user; | |
| public cls_links links; | |
| public cls_application application; | |
| public cls_organization organization; | |
| public cls_environment environment; | |
| } | |
| class cls_user { | |
| public String userId; //00590000000tQBwAAM | |
| public String userName; //lakshay.katney@main.com | |
| public String firstName; //Lakshay | |
| public String lastName; //Katney | |
| public String email; //lakshay.katney@gmail.com | |
| public String fullName; //Lakshay Katney | |
| public String locale; //en_US | |
| public String language; //en_US | |
| public String timeZone; //America/Los_Angeles | |
| public String profileId; //00e90000000sbeO | |
| public String roleId; //00E90000000oicG | |
| public String userType; //STANDARD | |
| public String currencyISOCode; //USD | |
| public String profilePhotoUrl; //https://c.ap1.content.force.com/profilephoto/729900000005sLc/F | |
| public String profileThumbnailUrl; //https://c.ap1.content.force.com/profilephoto/729900000005sLc/T | |
| public cls_siteUrl siteUrl; | |
| public cls_siteUrlPrefix siteUrlPrefix; | |
| public cls_networkId networkId; | |
| public boolean accessibilityModeEnabled; | |
| public boolean isDefaultNetwork; | |
| } | |
| class cls_siteUrl { | |
| } | |
| class cls_siteUrlPrefix { | |
| } | |
| class cls_networkId { | |
| } | |
| class cls_links { | |
| public String loginUrl; //https://login.salesforce.com/ | |
| public String enterpriseUrl; ///services/Soap/c/34.0/00D90000000azEO | |
| public String metadataUrl; ///services/Soap/m/34.0/00D90000000azEO | |
| public String partnerUrl; ///services/Soap/u/34.0/00D90000000azEO | |
| public String restUrl; ///services/data/v34.0/ | |
| public String sobjectUrl; ///services/data/v34.0/sobjects/ | |
| public String searchUrl; ///services/data/v34.0/search/ | |
| public String queryUrl; ///services/data/v34.0/query/ | |
| public String recentItemsUrl; ///services/data/v34.0/recent/ | |
| public String chatterFeedsUrl; ///services/data/v31.0/chatter/feeds | |
| public String chatterGroupsUrl; ///services/data/v34.0/chatter/groups | |
| public String chatterUsersUrl; ///services/data/v34.0/chatter/users | |
| public String chatterFeedItemsUrl; ///services/data/v31.0/chatter/feed-items | |
| public String userUrl; ///00590000000tQBwAAM | |
| } | |
| class cls_application { | |
| public String name; //Idea Vote | |
| public String canvasUrl; //https://lk-main.ap1.visual.force.com/apex/Canvas_Vote | |
| public String applicationId; //06P90000000VAyj | |
| public String version; //1.0 | |
| public String authType; //SIGNED_REQUEST | |
| public String referenceId; //09H90000000TcYE | |
| public cls_options[] options; | |
| public String samlInitiationMethod; //None | |
| public String developerName; //Idea_Vote | |
| public boolean isInstalledPersonalApp; | |
| public String namespace; //lk_main | |
| } | |
| class cls_options { | |
| } | |
| class cls_organization { | |
| public String organizationId; //00D90000000azEOEAY | |
| public String name; //Unneeded value | |
| public boolean multicurrencyEnabled; | |
| public String namespacePrefix; //lk_main | |
| public String currencyIsoCode; //USD | |
| } | |
| class cls_environment { | |
| public String locationUrl; //https://ap1.salesforce.com/_ui/core/chatter/ui/ChatterPage | |
| public String displayLocation; //ChatterFeed | |
| public cls_sublocation sublocation; | |
| public String uiTheme; //Theme3 | |
| public cls_dimensions dimensions; | |
| public cls_parameters parameters; | |
| public cls_record record; | |
| public cls_version version; | |
| } | |
| class cls_sublocation { | |
| } | |
| class cls_dimensions { | |
| public String width; //100% | |
| public String height; //250px | |
| public String maxWidth; //final | |
| public String maxHeight; //1000px | |
| public String clientWidth; //0px | |
| public String clientHeight; //0px | |
| } | |
| class cls_parameters { | |
| public String id; //087900000008Zli | |
| } | |
| class cls_record { | |
| public String Id; //0D59000001lbhaXCAQ | |
| public cls_attributes attributes; | |
| } | |
| class cls_attributes { | |
| public String type; //FeedItem | |
| public String url; ///services/data/v34.0/sobjects/FeedItem/0D59000001lbhaXCAQ | |
| } | |
| class cls_version { | |
| public String season; //SUMMER | |
| public String api; //34.0 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment