Skip to content

Instantly share code, notes, and snippets.

@gcimmino
Last active October 2, 2015 13:09
Show Gist options
  • Save gcimmino/d088b94a7b37cae63b2e to your computer and use it in GitHub Desktop.
Save gcimmino/d088b94a7b37cae63b2e to your computer and use it in GitHub Desktop.
bsmart oauth2 client flow
require 'rest-client'
require 'json'
client_id = '4ea1b...'
client_secret = 'a2982...'
code = '7fad4488afa56cefdefa7ff6ff0bd3a9e2d26b7648672c4bba7de5a0427bd6c7'
response = RestClient.post "https://bsmart.it/oauth/token", {
code: code,
client_id: client_id,
client_secret: client_secret,
grant_type: 'authorization_code',
redirect_uri: callback
}
response = JSON.parse(response)
# => {"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9..","token_type":"bearer","created_at":1433345888}
reponse["access_token"]
# => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9..."
RestClient.get 'https://bsmart.it/api/v4/user/me.json', { 'Authorization' => "Bearer #{token}" }
# => "{"id":1,"name":"Mario","surname":"Rossi","roles":["student"],"created_at":"2015-06-01T09:51:35.407Z","updated_at":"2015-06-01T09:51:35.758Z","email":"mrossi@dominio.it"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment