Skip to content

Instantly share code, notes, and snippets.

@maxwellE
Created December 9, 2013 23:33
Show Gist options
  • Save maxwellE/7883066 to your computer and use it in GitHub Desktop.
Save maxwellE/7883066 to your computer and use it in GitHub Desktop.
Gumroad OAuth2 sample code, uses the OAuth2 Gem https://github.com/intridea/oauth2
require 'oauth2'
client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org')
client.auth_code.authorize_url(:redirect_uri => 'http://localhost:8080/oauth2/callback')
# => "https://example.org/oauth/authorization?response_type=code&client_id=client_id&redirect_uri=http://localhost:8080/oauth2/callback"
token = client.auth_code.get_token('authorization_code_value', :redirect_uri => 'http://localhost:8080/oauth2/callback', :headers => {'Authorization' => 'Basic some_password'})
response = token.get('/api/resource', :params => { 'query_foo' => 'bar' })
response.class.name
# => OAuth2::Response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment