Created
March 1, 2013 22:09
-
-
Save jookyboi/5068303 to your computer and use it in GitHub Desktop.
Chrome extension for Salesforce.com REST API with OAuth2. http://www.anupshinde.com/salesforce-rest-api-chrome-extension
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
/* References | |
-- http://smus.com/oauth2-chrome-extensions/ | |
-- http://wiki.developerforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com | |
*/ | |
var sfdcAuth; // Holds the Auth2 object | |
chrome.app._inject_scope = "data_explorer_test"; /* This is used to determine what popup windows to close from this application. This must match the content_scripts->"matches" .If it does not match, the popups will stay open */ | |
/* Another and a better way to do this is to use the application id and change the oauth2 lib to tackle this - but we don't want to change the lib for now. Also it would be a good thing to create an autonomous client instead of the injection workaround - We'll keep it for later. */ | |
function docReady() { | |
sfdcAuth = new OAuth2('sfdc', { | |
//TODO= change clientid and secret | |
client_id: '--YOUR_CONSUMER_KEY--', | |
client_secret: '--CONSUMER_SECRET--', | |
api_scope: 'full' | |
}); | |
sfdcAuth.authorize(function(error) { | |
if(typeof(error)!='undefined') { | |
//console.log('Callback object'); | |
alert(error); | |
} | |
var _data_service_url = sfdcAuth.get('instance_url') | |
+"/services/data/v26.0/query/?q=SELECT Name FROM Account LIMIT 100"; | |
//+ '?oauth_token=' + sfdcAuth.getAccessToken(); | |
$.ajax({ | |
url: _data_service_url, | |
cache: false, | |
type: 'GET', | |
dataType: 'json', | |
headers: {'Authorization': 'OAuth ' + sfdcAuth.getAccessToken()}, | |
//data: data, | |
success: function(data){ | |
console.log(data); | |
var source = $("#accounts-list-template").html(); | |
t_accounts = Handlebars.compile(source); | |
var html = t_accounts(data); | |
$("#content").append(html); | |
} | |
}); | |
//alert('OAuth ' + myAuth.getAccessToken()); | |
}); | |
$("#clearToken").click(function() { | |
alert('Please logout of any existing SF sessions to use an another account'); | |
sfdcAuth.clearAccessToken(); | |
location.reload(); | |
}); | |
} | |
$(docReady); |
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
{ | |
"manifest_version": 2, | |
"name": "Force.com SOQL Explorer ", | |
"description": "Execute Force.com SOQL queries right from your browser", | |
"version": "1.0", | |
"content_scripts": [ | |
{ | |
"matches": | |
["https://login.salesforce.com/services/oauth2/success*data_explorer_test*"], | |
"js": ["/oauth2/oauth2_inject.js"], | |
"run_at": "document_start" | |
} | |
], | |
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", | |
"permissions": [ | |
"https://*.salesforce.com/" | |
], | |
"app": { | |
"launch": { | |
"local_path": "explorer.html" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment