Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created April 17, 2020 17:56
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 kyanny/cb8e386dbfea031617229bdf80b67ab4 to your computer and use it in GitHub Desktop.
Save kyanny/cb8e386dbfea031617229bdf80b67ab4 to your computer and use it in GitHub Desktop.
# https://getpocket.com/developer/docs/authentication
require 'net/http'
require 'uri'
def usage
puts <<USAGE
Usage:
$ ruby #{$0} <consumer_key>
USAGE
end
consumer_key = ARGV.first
unless consumer_key
usage
exit!
end
uri = URI.parse('https://getpocket.com/v3/oauth/request')
params = {
'consumer_key' => consumer_key,
'redirect_uri' => 'http://example.com/',
}
res = Net::HTTP.post_form(uri, params)
if res.code != '200'
puts res.body
exit!
end
query = Hash[URI.decode_www_form(res.body)]
code = query['code']
url = "https://getpocket.com/auth/authorize?request_token=#{code}&redirect_uri=http://example.com/"
system("open #{url}")
puts "Press any key if you have authenticated: "
STDIN.gets
uri = URI.parse('https://getpocket.com/v3/oauth/authorize')
params = {
'consumer_key' => consumer_key,
'code' => code,
}
res = Net::HTTP.post_form(uri, params)
pp Hash[URI.decode_www_form(res.body)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment