Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #54 from bodrovis/master
Browse files Browse the repository at this point in the history
Make TokenController customizable. Fixes #52
  • Loading branch information
schneems committed Dec 11, 2015
2 parents ecffe22 + e30aca5 commit 6e0fe4e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ gem "rails", rails

gem 'kramdown' # pure ruby markdown parser

gem 'jbuilder'

group :development, :test do
gem 'mocha', :require => false
gem 'timecop'
Expand Down
10 changes: 3 additions & 7 deletions app/controllers/opro/oauth/token_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ def create
# Find the client application
application = Opro::Oauth::ClientApp.authenticate(params[:client_id], params[:client_secret])

if application.present? && (auth_grant = auth_grant_for(application, params)).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 }
if application.present? && (@auth_grant = auth_grant_for(application, params)).present?
@auth_grant.refresh!
render :create
else
render_error debug_msg(params, application)
end
Expand Down
4 changes: 4 additions & 0 deletions app/views/opro/oauth/token/create.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
json.access_token @auth_grant.access_token
json.token_type Opro.token_type || 'bearer'
json.refresh_token @auth_grant.refresh_token
json.expires_in @auth_grant.expires_in
3 changes: 2 additions & 1 deletion lib/opro/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ def mount_opro_oauth(options = {})
controllers = options[:controllers] || {}

oauth_new_controller = controllers[:oauth_new] || 'opro/oauth/auth'
oauth_token_controller = controllers[:oauth_token] || 'opro/oauth/token'
get 'oauth/new' => "#{oauth_new_controller}#new", :as => 'oauth_new'
post 'oauth/authorize' => 'opro/oauth/auth#create', :as => 'oauth_authorize'
post 'oauth/token' => 'opro/oauth/token#create', :as => 'oauth_token'
post 'oauth/token' => "#{oauth_token_controller}#create", :as => 'oauth_token', :defaults => { :format => 'json' }

unless skip_routes.include?(:client_apps)
oauth_client_apps = controllers[:oauth_client_apps] ||'opro/oauth/client_app'
Expand Down
3 changes: 3 additions & 0 deletions opro.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
s.add_runtime_dependency(%q<kramdown>, [">= 0"])
s.add_runtime_dependency(%q<jbuilder>, ["~> 2.3"])
s.add_development_dependency(%q<mocha>, [">= 0"])
s.add_development_dependency(%q<timecop>, [">= 0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
Expand All @@ -145,6 +146,7 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<rails>, [">= 3.1.0"])
s.add_dependency(%q<kramdown>, [">= 0"])
s.add_dependency(%q<jbuilder>, ["~> 2.3"])
s.add_dependency(%q<mocha>, [">= 0"])
s.add_dependency(%q<timecop>, [">= 0"])
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
Expand All @@ -158,6 +160,7 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<rails>, [">= 3.1.0"])
s.add_dependency(%q<kramdown>, [">= 0"])
s.add_dependency(%q<jbuilder>, ["~> 2.3"])
s.add_dependency(%q<mocha>, [">= 0"])
s.add_dependency(%q<timecop>, [">= 0"])
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
Expand Down

0 comments on commit 6e0fe4e

Please sign in to comment.