Created
May 8, 2015 05:42
-
-
Save yutelin/c9b408ae0804f02de5ac to your computer and use it in GitHub Desktop.
Get MaiCoin access token example
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 = ENV['CLIENT_ID'] | |
client_secret= ENV['CLIENT_SECRET'] | |
redirect_uri = 'https://127.0.0.1' # this must match the url you set during registration | |
client_options = { | |
site: 'https://api.maicoin.com', | |
authorize_url: 'https://www.maicoin.com/oauth/authorize', | |
token_url: 'https://www.maicoin.com/oauth/token' | |
} | |
client = OAuth2::Client.new(client_id, client_secret, client_options) | |
`open "#{client.auth_code.authorize_url(redirect_uri: redirect_uri)}"` | |
print "Enter the code returned in the URL: " | |
code = STDIN.readline.chomp | |
token = client.auth_code.get_token(code, redirect_uri: redirect_uri) | |
response = token.get('/v1/user') | |
puts JSON.pretty_generate(JSON.parse(response.body)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment