Created
August 27, 2016 19:29
-
-
Save longlostnick/e17610f30dceda96d50c1f22c4386853 to your computer and use it in GitHub Desktop.
Quick script for OAuth2 dancin'
This file contains 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
require 'oauth2' | |
client_id = '' | |
client_secret = '' | |
login_server = 'https://test.salesforce.com' | |
redirect_uri = 'https://login.salesforce.com/services/oauth2/callback' | |
client = OAuth2::Client.new( | |
client_id, | |
client_secret, | |
site: login_server, | |
authorize_url: '/services/oauth2/authorize', | |
token_url: '/services/oauth2/token' | |
) | |
# STEP 1 | |
puts "1) Paste this URL into your browser where you are logged in to the relevant account:\n\n" | |
puts client.auth_code.authorize_url(redirect_uri: redirect_uri) | |
# STEP 2 | |
puts "\n\n2) Accept the authorization request in your browser." | |
# STEP 3 | |
puts "\n\n3) Copy the code param from the URL they redirect you to (including the ending '=='), paste it here and hit enter:\n" | |
code = gets.chomp.strip | |
access_token_obj = client.auth_code.get_token(code, redirect_uri: redirect_uri, token_method: :post) | |
# STEP 4 | |
puts "\n\nAccess Token is: #{access_token_obj.token}" | |
puts "Refresh token is: #{access_token_obj.refresh_token}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment