Class: Opro::Oauth::TokenController

Inherits:
OproController
  • Object
show all
Defined in:
app/controllers/opro/oauth/token_controller.rb

Overview

This controller is where clients can exchange codes and refresh_tokens for access_tokens

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/opro/oauth/token_controller.rb', line 9

def create
  # Find the client application
  application = Opro::Oauth::ClientApp.authenticate(params[:client_id], params[:client_secret])
  auth_grant  = auth_grant_for(application, params)

  if auth_grant.present?
    auth_grant.refresh!
    render :json => { access_token:  auth_grant.access_token,
                      # http://tools.ietf.org/html/rfc6749#section-5.1
                      token_type:    Opro.token_type || 'bearer',
                      refresh_token: auth_grant.refresh_token,
                      expires_in:    auth_grant.expires_in }
  else
    render_error debug_msg(params, application)
  end
end