Class: Oauth2Rails::Auth
Instance Method Summary collapse
-
#authorize_url ⇒ Object
SAMPLE AUTHORIZATION REQUEST GET: www.fitbit.com/oauth2/authorize?response_type=code&client_id=22942C& redirect_uri=http%3A%2F%2Fexample.com%2Fcallback& scope=activity%20nutrition%20heartrate.
-
#get_token(code) ⇒ Object
SAMPLE POST REQUEST POST: api.fitbit.com/oauth2/token BODY: client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Fcallback&code=1234567890 HEADERS: Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ= Content-Type: application/x-www-form-urlencoded.
-
#initialize(options = {}) ⇒ Auth
constructor
A new instance of Auth.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Auth
Returns a new instance of Auth.
6 7 8 9 |
# File 'lib/oauth2_rails/auth.rb', line 6 def initialize( = {}) @state = [:state] super() end |
Instance Method Details
#authorize_url ⇒ Object
SAMPLE AUTHORIZATION REQUEST GET: www.fitbit.com/oauth2/authorize?response_type=code&client_id=22942C&
redirect_uri=http%3A%2F%2Fexample.com%2Fcallback&
scope=activity%20nutrition%20heartrate
15 16 17 18 |
# File 'lib/oauth2_rails/auth.rb', line 15 def body = { response_type: 'code', client_id: @oauth_id, redirect_uri: @redirect_uri, scope: @scope, state: @state } connection(@authorize_site).build_url(@authorize_path, body).to_s end |
#get_token(code) ⇒ Object
SAMPLE POST REQUEST POST: api.fitbit.com/oauth2/token BODY: client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Fcallback&code=1234567890 HEADERS: Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
25 26 27 28 29 |
# File 'lib/oauth2_rails/auth.rb', line 25 def get_token(code) body = { grant_type: 'authorization_code', client_id: @oauth_id, redirect_uri: @redirect_uri, code: code } tokens = call(:post, @token_path, body: body) User.new(tokens.json_body) end |