Skip to content

Instantly share code, notes, and snippets.

@scottserok
Last active November 11, 2020 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottserok/bed65b39509b78af8595c2aab3ec36bd to your computer and use it in GitHub Desktop.
Save scottserok/bed65b39509b78af8595c2aab3ec36bd to your computer and use it in GitHub Desktop.
Revoke a Salesforce OAuth token
#!/usr/bin/env ruby
# We revoke the OAuth token by sending an HTTP POST to salesforce.com/services/oauth2/revoke
# Usage
# ruby revoke.rb myOauthtoken
#
# https://help.salesforce.com/articleView?id=remoteaccess_revoke_token.htm&type=0
#
# POST /revoke HTTP/1.1
# Host: https://test.salesforce.com/services/oauth2/revoke
# Content-Type: application/x-www-form-urlencoded
#
# token=currenttoken
require 'bundler/inline'
require 'json'
gemfile do
gem 'faraday'
end
token = ARGV.shift
puts "Revoking token=#{token}\n"
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
body = "token=#{token}"
location = 'https://test.salesforce.com/services/oauth2/revoke'
response = Faraday.post(location, body, headers)
if response.status == 302
location = response.headers['location']
response = Faraday.post(location, body, headers)
end
if response.status == 202
puts :done
else
print response.headers.to_json
puts
puts response.body
puts
puts response.status
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment