Last active
November 11, 2020 01:06
-
-
Save scottserok/bed65b39509b78af8595c2aab3ec36bd to your computer and use it in GitHub Desktop.
Revoke a Salesforce OAuth token
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
#!/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