opro 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/CHANGELOG.md +7 -1
- data/README.md +1 -5
- data/VERSION +1 -1
- data/app/controllers/{oauth → opro/oauth}/auth_controller.rb +8 -8
- data/app/controllers/opro/oauth/client_app_controller.rb +24 -0
- data/app/controllers/{oauth → opro/oauth}/docs_controller.rb +2 -2
- data/app/controllers/{oauth → opro/oauth}/tests_controller.rb +1 -1
- data/app/controllers/{oauth → opro/oauth}/token_controller.rb +4 -4
- data/app/models/{oauth/access_grant.rb → opro/oauth/auth_grant.rb} +2 -2
- data/app/models/{oauth → opro/oauth}/client_app.rb +2 -2
- data/app/views/{oauth → opro/oauth}/auth/new.html.erb +1 -1
- data/app/views/{oauth → opro/oauth}/client_app/create.html.erb +0 -0
- data/app/views/{oauth → opro/oauth}/client_app/index.html.erb +0 -0
- data/app/views/{oauth → opro/oauth}/client_app/new.html.erb +1 -1
- data/app/views/{oauth → opro/oauth}/docs/index.html.erb +0 -0
- data/app/views/{oauth → opro/oauth}/docs/markdown/curl.md.erb +0 -0
- data/app/views/{oauth → opro/oauth}/docs/markdown/oauth.md.erb +0 -0
- data/app/views/{oauth → opro/oauth}/docs/markdown/permissions.md.erb +0 -0
- data/app/views/{oauth → opro/oauth}/docs/markdown/quick_start.md.erb +0 -0
- data/app/views/{oauth → opro/oauth}/docs/markdown/refresh_tokens.md.erb +0 -0
- data/app/views/{oauth → opro/oauth}/docs/show.html.erb +0 -0
- data/app/views/{oauth → opro/oauth}/tests/index.html.erb +0 -0
- data/config/routes.rb +3 -0
- data/lib/generators/active_record/opro_generator.rb +2 -2
- data/{test/dummy/db/migrate/20120514060322_create_opro_access_grants.rb → lib/generators/active_record/templates/auth_grants.rb} +1 -1
- data/lib/generators/active_record/templates/{client_applications.rb → client_apps.rb} +1 -1
- data/lib/opro.rb +2 -0
- data/lib/opro/controllers/application_controller_helper.rb +5 -3
- data/lib/opro/engine.rb +0 -2
- data/lib/opro/rails/routes.rb +8 -6
- data/opro.gemspec +25 -25
- data/test/controllers/permissions_test.rb +4 -4
- data/{lib/generators/active_record/templates/access_grants.rb → test/dummy/db/migrate/20120618085751_create_opro_auth_grants.rb} +1 -1
- data/test/dummy/db/migrate/{20120514060323_create_opro_client_applications.rb → 20120618085752_create_opro_client_apps.rb} +1 -1
- data/test/integration/action_dispatch/auth_controller_test.rb +1 -1
- data/test/integration/action_dispatch/refresh_token_test.rb +1 -1
- data/test/integration/auth_controller_test.rb +2 -2
- data/test/integration/client_app_controller_test.rb +2 -2
- data/test/integration/oauth_test.rb +9 -0
- data/test/test_helper.rb +6 -2
- metadata +52 -52
- data/app/controllers/oauth/client_app_controller.rb +0 -24
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
## Stop, Read This
|
2
|
-
|
3
|
-
If you want to use this, do so at your own risk. I'm vetting it on some development and production applications, when it is ready for consumption and contribution, I'll remove this. If you want to be notified when that happens let me know [@schneems](http://twitter.com/schneems). For now this should be considered a toy, and enjoyed as such :)
|
4
|
-
|
5
1
|
## Opro
|
6
2
|
|
7
|
-
A Rails Engine that turns your app into an [Oauth2](http://oauth.net/2/) Provider.
|
3
|
+
A production ready Rails Engine that turns your app into an [Oauth2](http://oauth.net/2/) Provider.
|
8
4
|
|
9
5
|
* [Demo OAuth Provider app with Opro](http://opro-demo.herokuapp.com/) on Heroku
|
10
6
|
* [Built in Opro docs](http://opro-demo.herokuapp.com/oauth_docs)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class Oauth::AuthController < OproController
|
1
|
+
class Opro::Oauth::AuthController < OproController
|
2
2
|
before_filter :opro_authenticate_user!
|
3
3
|
before_filter :ask_user!, :only => [:create]
|
4
4
|
|
5
5
|
|
6
6
|
def new
|
7
7
|
@redirect_uri = params[:redirect_uri]
|
8
|
-
@client_app = Oauth::ClientApp.find_by_app_id(params[:client_id])
|
8
|
+
@client_app = Opro::Oauth::ClientApp.find_by_app_id(params[:client_id])
|
9
9
|
@scopes = scope_from_params(params)
|
10
10
|
end
|
11
11
|
|
@@ -14,9 +14,9 @@ class Oauth::AuthController < OproController
|
|
14
14
|
# :ask_user! is called before creating a new authorization, this allows us to redirect
|
15
15
|
def create
|
16
16
|
# find or create an auth_grant for a given user
|
17
|
-
application = Oauth::ClientApp.find_by_app_id(params[:client_id])
|
18
|
-
access_grant = Oauth::AuthGrant.where( :user_id => current_user.id, :application_id => application.id).first
|
19
|
-
access_grant ||= Oauth::AuthGrant.create(:user => current_user, :application => application)
|
17
|
+
application = Opro::Oauth::ClientApp.find_by_app_id(params[:client_id])
|
18
|
+
access_grant = Opro::Oauth::AuthGrant.where( :user_id => current_user.id, :application_id => application.id).first
|
19
|
+
access_grant ||= Opro::Oauth::AuthGrant.create(:user => current_user, :application => application)
|
20
20
|
|
21
21
|
|
22
22
|
# add permission changes if there are any
|
@@ -41,14 +41,14 @@ class Oauth::AuthController < OproController
|
|
41
41
|
|
42
42
|
# if the request did not come from a form within the application, render the user form
|
43
43
|
@redirect_uri ||= params[:redirect_uri]
|
44
|
-
@client_app ||= Oauth::ClientApp.find_by_app_id(params[:client_id])
|
44
|
+
@client_app ||= Opro::Oauth::ClientApp.find_by_app_id(params[:client_id])
|
45
45
|
redirect_to oauth_new_path(params)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def user_granted_access_before?(user, params)
|
50
|
-
@client_app ||= Oauth::ClientApp.find_by_app_id(params[:client_id])
|
51
|
-
Oauth::AuthGrant.where(:application_id => @client_app.id, :user_id => user.id).present?
|
50
|
+
@client_app ||= Opro::Oauth::ClientApp.find_by_app_id(params[:client_id])
|
51
|
+
Opro::Oauth::AuthGrant.where(:application_id => @client_app.id, :user_id => user.id).present?
|
52
52
|
end
|
53
53
|
|
54
54
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Opro::Oauth::ClientAppController < OproController
|
2
|
+
before_filter :opro_authenticate_user!
|
3
|
+
|
4
|
+
def new
|
5
|
+
@client_app = Opro::Oauth::ClientApp.new
|
6
|
+
end
|
7
|
+
|
8
|
+
# Show all client applications belonging to the current user
|
9
|
+
def index
|
10
|
+
@client_apps = Opro::Oauth::ClientApp.where(:user_id => current_user.id)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def create
|
15
|
+
@client_app = Opro::Oauth::ClientApp.find_by_user_id_and_name(current_user.id, params[:opro_oauth_client_app][:name])
|
16
|
+
@client_app ||= Opro::Oauth::ClientApp.create_with_user_and_name(current_user, params[:opro_oauth_client_app][:name])
|
17
|
+
if @client_app.save
|
18
|
+
# do nothing
|
19
|
+
else
|
20
|
+
render :new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'bluecloth'
|
3
3
|
|
4
|
-
OPRO_MD_ROOT=File.join(File.dirname(__FILE__), '
|
4
|
+
OPRO_MD_ROOT=File.join(File.dirname(__FILE__), '../../../views/opro/oauth/docs/markdown/')
|
5
5
|
|
6
6
|
|
7
|
-
class Oauth::DocsController < OproController
|
7
|
+
class Opro::Oauth::DocsController < OproController
|
8
8
|
helper_method :render_doc
|
9
9
|
|
10
10
|
def index
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# This controller is where clients can exchange
|
2
2
|
# codes and refresh_tokens for access_tokens
|
3
3
|
|
4
|
-
class Oauth::TokenController < OproController
|
4
|
+
class Opro::Oauth::TokenController < OproController
|
5
5
|
before_filter :opro_authenticate_user!, :except => [:create]
|
6
6
|
skip_before_filter :verify_authenticity_token, :only => [:create]
|
7
7
|
|
8
8
|
|
9
9
|
def create
|
10
10
|
# Find the client application
|
11
|
-
application = Oauth::ClientApp.authenticate(params[:client_id], params[:client_secret])
|
11
|
+
application = Opro::Oauth::ClientApp.authenticate(params[:client_id], params[:client_secret])
|
12
12
|
|
13
13
|
if application.nil?
|
14
14
|
render :json => {:error => "Could not find application based on client_id=#{params[:client_id]}
|
@@ -18,9 +18,9 @@ class Oauth::TokenController < OproController
|
|
18
18
|
|
19
19
|
|
20
20
|
if params[:code]
|
21
|
-
auth_grant = Oauth::AuthGrant.authenticate(params[:code], application.id)
|
21
|
+
auth_grant = Opro::Oauth::AuthGrant.authenticate(params[:code], application.id)
|
22
22
|
else
|
23
|
-
auth_grant = Oauth::AuthGrant.refresh_tokens!(params[:refresh_token], application.id)
|
23
|
+
auth_grant = Opro::Oauth::AuthGrant.refresh_tokens!(params[:refresh_token], application.id)
|
24
24
|
end
|
25
25
|
|
26
26
|
if auth_grant.nil?
|
@@ -24,5 +24,5 @@ I Authorize <%= @client_app.name %> to:
|
|
24
24
|
<%= f.submit 'Authorize This Application', :id => 'oauthAuthorize' %>
|
25
25
|
<%- end -%>
|
26
26
|
|
27
|
-
<%= button_to 'Decline this Request', request.referrer, :id => 'oauthNoAuthorize' %>
|
27
|
+
<%= button_to 'Decline this Request', request.referrer||'/', :id => 'oauthNoAuthorize' %>
|
28
28
|
|
File without changes
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<h2>Create An OAuth Client App</h2>
|
2
2
|
<div>
|
3
|
-
<%= form_for @client_app do |f| %>
|
3
|
+
<%= form_for @client_app, :url => oauth_client_apps_path do |f| %>
|
4
4
|
<%= f.label :name %>
|
5
5
|
<%= f.text_field :name, :placeholder => 'App Name' %>
|
6
6
|
<%= f.submit 'Create OAuth Client', :id => 'submitApp' %>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/config/routes.rb
CHANGED
@@ -20,8 +20,8 @@ module ActiveRecord
|
|
20
20
|
|
21
21
|
|
22
22
|
def copy_migrations
|
23
|
-
migration_template "
|
24
|
-
migration_template "
|
23
|
+
migration_template "auth_grants.rb", "db/migrate/create_opro_auth_grants.rb"
|
24
|
+
migration_template "client_apps.rb", "db/migrate/create_opro_client_apps.rb"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/opro.rb
CHANGED
@@ -58,15 +58,17 @@ module Opro
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def oauth_access_grant
|
61
|
-
@oauth_access_grant ||= Oauth::AuthGrant.find_for_token(params[:access_token])
|
61
|
+
@oauth_access_grant ||= Opro::Oauth::AuthGrant.find_for_token(params[:access_token])
|
62
62
|
end
|
63
63
|
|
64
64
|
def oauth_client_app
|
65
|
-
|
65
|
+
return false if oauth_access_grant.blank?
|
66
|
+
@oauth_client_app ||= oauth_access_grant.client_application
|
66
67
|
end
|
67
68
|
|
68
69
|
def oauth_user
|
69
|
-
|
70
|
+
return false if oauth_access_grant.blank?
|
71
|
+
@oauth_user ||= oauth_access_grant.user
|
70
72
|
end
|
71
73
|
|
72
74
|
def oauth_auth!
|
data/lib/opro/engine.rb
CHANGED
data/lib/opro/rails/routes.rb
CHANGED
@@ -4,14 +4,16 @@ module ActionDispatch::Routing
|
|
4
4
|
# generate all needed routes for oauth
|
5
5
|
def mount_opro_oauth(options = {})
|
6
6
|
skip_routes = options[:except].is_a?(Array) ? options[:except] : [options[:except]]
|
7
|
+
controllers = options[:controllers] || {}
|
7
8
|
|
8
|
-
match 'oauth/new' => 'oauth/auth#new', :as => 'oauth_new'
|
9
|
-
match 'oauth/authorize' => 'oauth/auth#create', :as => 'oauth_authorize'
|
10
|
-
match 'oauth/token' => 'oauth/token#create', :as => 'oauth_token'
|
9
|
+
match 'oauth/new' => 'opro/oauth/auth#new', :as => 'oauth_new'
|
10
|
+
match 'oauth/authorize' => 'opro/oauth/auth#create', :as => 'oauth_authorize'
|
11
|
+
match 'oauth/token' => 'opro/oauth/token#create', :as => 'oauth_token'
|
11
12
|
|
12
|
-
resources :oauth_docs, :controller => 'oauth/docs' unless skip_routes.include?(:docs)
|
13
|
-
resources :oauth_tests, :controller => 'oauth/tests' unless skip_routes.include?(:tests)
|
14
|
-
resources :oauth_client_apps, :controller => 'oauth/client_app' unless skip_routes.include?(:client_apps)
|
13
|
+
resources :oauth_docs, :controller => controllers[:oauth_docs] ||'opro/oauth/docs' unless skip_routes.include?(:docs)
|
14
|
+
resources :oauth_tests, :controller => controllers[:oauth_tests] ||'opro/oauth/tests' unless skip_routes.include?(:tests)
|
15
|
+
resources :oauth_client_apps, :controller => controllers[:oauth_client_apps]||'opro/oauth/client_app' unless skip_routes.include?(:client_apps)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
data/opro.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "opro"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["schneems"]
|
12
|
-
s.date = "2012-06-
|
12
|
+
s.date = "2012-06-19"
|
13
13
|
s.description = " Enable OAuth clients (iphone, android, web sites, etc.) to access and use your Rails application, what you do with it is up to you"
|
14
14
|
s.email = "richard.schneeman@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,30 +24,30 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.md",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
-
"app/controllers/oauth/auth_controller.rb",
|
28
|
-
"app/controllers/oauth/client_app_controller.rb",
|
29
|
-
"app/controllers/oauth/docs_controller.rb",
|
30
|
-
"app/controllers/oauth/tests_controller.rb",
|
31
|
-
"app/controllers/oauth/token_controller.rb",
|
27
|
+
"app/controllers/opro/oauth/auth_controller.rb",
|
28
|
+
"app/controllers/opro/oauth/client_app_controller.rb",
|
29
|
+
"app/controllers/opro/oauth/docs_controller.rb",
|
30
|
+
"app/controllers/opro/oauth/tests_controller.rb",
|
31
|
+
"app/controllers/opro/oauth/token_controller.rb",
|
32
32
|
"app/controllers/opro_controller.rb",
|
33
|
-
"app/models/oauth/
|
34
|
-
"app/models/oauth/client_app.rb",
|
35
|
-
"app/views/oauth/auth/new.html.erb",
|
36
|
-
"app/views/oauth/client_app/create.html.erb",
|
37
|
-
"app/views/oauth/client_app/index.html.erb",
|
38
|
-
"app/views/oauth/client_app/new.html.erb",
|
39
|
-
"app/views/oauth/docs/index.html.erb",
|
40
|
-
"app/views/oauth/docs/markdown/curl.md.erb",
|
41
|
-
"app/views/oauth/docs/markdown/oauth.md.erb",
|
42
|
-
"app/views/oauth/docs/markdown/permissions.md.erb",
|
43
|
-
"app/views/oauth/docs/markdown/quick_start.md.erb",
|
44
|
-
"app/views/oauth/docs/markdown/refresh_tokens.md.erb",
|
45
|
-
"app/views/oauth/docs/show.html.erb",
|
46
|
-
"app/views/oauth/tests/index.html.erb",
|
33
|
+
"app/models/opro/oauth/auth_grant.rb",
|
34
|
+
"app/models/opro/oauth/client_app.rb",
|
35
|
+
"app/views/opro/oauth/auth/new.html.erb",
|
36
|
+
"app/views/opro/oauth/client_app/create.html.erb",
|
37
|
+
"app/views/opro/oauth/client_app/index.html.erb",
|
38
|
+
"app/views/opro/oauth/client_app/new.html.erb",
|
39
|
+
"app/views/opro/oauth/docs/index.html.erb",
|
40
|
+
"app/views/opro/oauth/docs/markdown/curl.md.erb",
|
41
|
+
"app/views/opro/oauth/docs/markdown/oauth.md.erb",
|
42
|
+
"app/views/opro/oauth/docs/markdown/permissions.md.erb",
|
43
|
+
"app/views/opro/oauth/docs/markdown/quick_start.md.erb",
|
44
|
+
"app/views/opro/oauth/docs/markdown/refresh_tokens.md.erb",
|
45
|
+
"app/views/opro/oauth/docs/show.html.erb",
|
46
|
+
"app/views/opro/oauth/tests/index.html.erb",
|
47
47
|
"config/routes.rb",
|
48
48
|
"lib/generators/active_record/opro_generator.rb",
|
49
|
-
"lib/generators/active_record/templates/
|
50
|
-
"lib/generators/active_record/templates/
|
49
|
+
"lib/generators/active_record/templates/auth_grants.rb",
|
50
|
+
"lib/generators/active_record/templates/client_apps.rb",
|
51
51
|
"lib/generators/opro/install_generator.rb",
|
52
52
|
"lib/generators/templates/opro.rb",
|
53
53
|
"lib/opro.rb",
|
@@ -87,8 +87,8 @@ Gem::Specification.new do |s|
|
|
87
87
|
"test/dummy/config/locales/en.yml",
|
88
88
|
"test/dummy/config/routes.rb",
|
89
89
|
"test/dummy/db/migrate/20120408163038_devise_create_users.rb",
|
90
|
-
"test/dummy/db/migrate/
|
91
|
-
"test/dummy/db/migrate/
|
90
|
+
"test/dummy/db/migrate/20120618085751_create_opro_auth_grants.rb",
|
91
|
+
"test/dummy/db/migrate/20120618085752_create_opro_client_apps.rb",
|
92
92
|
"test/dummy/db/schema.rb",
|
93
93
|
"test/dummy/public/404.html",
|
94
94
|
"test/dummy/public/422.html",
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class Oauth::TestsControllerTest < ActionController::TestCase
|
4
|
-
tests Oauth::TestsController
|
3
|
+
class Opro::Oauth::TestsControllerTest < ActionController::TestCase
|
4
|
+
tests Opro::Oauth::TestsController
|
5
5
|
include Devise::TestHelpers
|
6
6
|
|
7
7
|
setup do
|
@@ -13,7 +13,7 @@ class Oauth::TestsControllerTest < ActionController::TestCase
|
|
13
13
|
permissions = {'write' => true}
|
14
14
|
@auth_grant.update_attributes(:permissions => permissions)
|
15
15
|
|
16
|
-
post :create, access_token => @auth_grant.access_token, format => :json
|
16
|
+
post :create, :access_token => @auth_grant.access_token, :format => :json
|
17
17
|
assert_response :success
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ class Oauth::TestsControllerTest < ActionController::TestCase
|
|
21
21
|
test "access_token with NO write ability can NOT POST" do
|
22
22
|
permissions = {:write => false}
|
23
23
|
@auth_grant.update_attributes(:permissions => permissions)
|
24
|
-
post :create, access_token => @auth_grant.access_token, format => :json
|
24
|
+
post :create, :access_token => @auth_grant.access_token, :format => :json
|
25
25
|
assert_response 401
|
26
26
|
end
|
27
27
|
end
|
@@ -43,7 +43,7 @@ class AuthControllerTest < ActionDispatch::IntegrationTest
|
|
43
43
|
assert_equal 302, status
|
44
44
|
follow_redirect!
|
45
45
|
assert_equal @redirect_uri, path
|
46
|
-
auth_grant = Oauth::AuthGrant.find(auth_grant.id)
|
46
|
+
auth_grant = Opro::Oauth::AuthGrant.find(auth_grant.id)
|
47
47
|
|
48
48
|
refute auth_grant.permissions.has_key?(permissions.keys.first)
|
49
49
|
end
|
@@ -45,7 +45,7 @@ class RefreshTokenTest < ActionDispatch::IntegrationTest
|
|
45
45
|
refute_equal json_hash['expires_in'], @auth_grant.expires_in
|
46
46
|
|
47
47
|
|
48
|
-
auth_grant = Oauth::AuthGrant.find(@auth_grant.id)
|
48
|
+
auth_grant = Opro::Oauth::AuthGrant.find(@auth_grant.id)
|
49
49
|
assert_equal json_hash['access_token'], auth_grant.access_token
|
50
50
|
assert_equal json_hash['refresh_token'], auth_grant.refresh_token
|
51
51
|
assert_equal json_hash['expires_in'], auth_grant.expires_in
|
@@ -21,7 +21,7 @@ class CapybaraAuthControllerTest < ActiveSupport::IntegrationCase
|
|
21
21
|
click_button 'oauthAuthorize'
|
22
22
|
end
|
23
23
|
|
24
|
-
access_grant = Oauth::AuthGrant.where(:user_id => @user.id, :application_id => @app.id).first
|
24
|
+
access_grant = Opro::Oauth::AuthGrant.where(:user_id => @user.id, :application_id => @app.id).first
|
25
25
|
assert_equal @redirect_uri, current_path
|
26
26
|
assert access_grant.present?
|
27
27
|
assert access_grant.can?(:write) # write access is checked by default
|
@@ -32,7 +32,7 @@ class CapybaraAuthControllerTest < ActiveSupport::IntegrationCase
|
|
32
32
|
|
33
33
|
uncheck('permissions_write') # uncheck write access
|
34
34
|
click_button 'oauthAuthorize'
|
35
|
-
access_grant = Oauth::AuthGrant.where(:user_id => @user.id, :application_id => @app.id).first
|
35
|
+
access_grant = Opro::Oauth::AuthGrant.where(:user_id => @user.id, :application_id => @app.id).first
|
36
36
|
refute access_grant.can?(:write)
|
37
37
|
end
|
38
38
|
end
|
@@ -11,12 +11,12 @@ class ClientAppControllerTest < ActiveSupport::IntegrationCase
|
|
11
11
|
as_user(user).visit new_oauth_client_app_path
|
12
12
|
assert_equal '/oauth_client_apps/new', current_path
|
13
13
|
|
14
|
-
fill_in '
|
14
|
+
fill_in 'opro_oauth_client_app_name', :with => rand_name
|
15
15
|
|
16
16
|
click_button 'submitApp'
|
17
17
|
assert_equal '/oauth_client_apps', current_path
|
18
18
|
|
19
|
-
last_client = Oauth::ClientApp.order(:created_at).last
|
19
|
+
last_client = Opro::Oauth::ClientApp.order(:created_at).last
|
20
20
|
assert has_content?(last_client.name)
|
21
21
|
assert has_content?(last_client.client_id)
|
22
22
|
assert has_content?(last_client.client_secret)
|
@@ -15,4 +15,13 @@ class CapybaraOauthTest < ActiveSupport::IntegrationCase
|
|
15
15
|
assert has_content?('User is logged in')
|
16
16
|
end
|
17
17
|
|
18
|
+
test 'invalid auth token shows user as logged OUT' do
|
19
|
+
user = create_user
|
20
|
+
auth_grant = create_auth_grant_for_user(user)
|
21
|
+
access_token = auth_grant.access_token + "foo"
|
22
|
+
visit "/?access_token=#{access_token}"
|
23
|
+
save_and_open_page
|
24
|
+
assert has_content?('NO logged in users')
|
25
|
+
end
|
26
|
+
|
18
27
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Configure Rails Envinronment
|
2
2
|
ENV["RAILS_ENV"] = "test"
|
3
3
|
|
4
|
+
if RUBY_VERSION >= "1.9"
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start 'rails'
|
7
|
+
end
|
4
8
|
|
5
9
|
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
6
10
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
@@ -59,7 +63,7 @@ end
|
|
59
63
|
def create_client_app(options= {})
|
60
64
|
user = options[:user] || create_user
|
61
65
|
name = options[:name] || rand_name
|
62
|
-
Oauth::ClientApp.create_with_user_and_name(user, name)
|
66
|
+
Opro::Oauth::ClientApp.create_with_user_and_name(user, name)
|
63
67
|
end
|
64
68
|
|
65
69
|
def user_with_client_app
|
@@ -71,7 +75,7 @@ end
|
|
71
75
|
def create_auth_grant_for_user(user = nil, app = nil)
|
72
76
|
app ||= create_client_app
|
73
77
|
user ||= create_user
|
74
|
-
Oauth::AuthGrant.create(:user => user, :application => app)
|
78
|
+
Opro::Oauth::AuthGrant.create(:user => user, :application => app)
|
75
79
|
end
|
76
80
|
|
77
81
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70273794750300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70273794750300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70273794749360 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70273794749360
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bluecloth
|
38
|
-
requirement: &
|
38
|
+
requirement: &70273794748420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70273794748420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70273794747460 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70273794747460
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: timecop
|
60
|
-
requirement: &
|
60
|
+
requirement: &70273794746540 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70273794746540
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: jeweler
|
71
|
-
requirement: &
|
71
|
+
requirement: &70273794745720 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.6.4
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70273794745720
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: bundler
|
82
|
-
requirement: &
|
82
|
+
requirement: &70273794745020 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 1.1.3
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70273794745020
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: capybara
|
93
|
-
requirement: &
|
93
|
+
requirement: &70273794744280 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.4.0
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70273794744280
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: sqlite3
|
104
|
-
requirement: &
|
104
|
+
requirement: &70273794743560 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70273794743560
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: launchy
|
115
|
-
requirement: &
|
115
|
+
requirement: &70273794742780 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70273794742780
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: devise
|
126
|
-
requirement: &
|
126
|
+
requirement: &70273794742200 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70273794742200
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: rcov
|
137
|
-
requirement: &
|
137
|
+
requirement: &70273794741600 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: '0'
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70273794741600
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: simplecov
|
148
|
-
requirement: &
|
148
|
+
requirement: &70273794740720 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,7 +153,7 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70273794740720
|
157
157
|
description: ! ' Enable OAuth clients (iphone, android, web sites, etc.) to access
|
158
158
|
and use your Rails application, what you do with it is up to you'
|
159
159
|
email: richard.schneeman@gmail.com
|
@@ -170,30 +170,30 @@ files:
|
|
170
170
|
- README.md
|
171
171
|
- Rakefile
|
172
172
|
- VERSION
|
173
|
-
- app/controllers/oauth/auth_controller.rb
|
174
|
-
- app/controllers/oauth/client_app_controller.rb
|
175
|
-
- app/controllers/oauth/docs_controller.rb
|
176
|
-
- app/controllers/oauth/tests_controller.rb
|
177
|
-
- app/controllers/oauth/token_controller.rb
|
173
|
+
- app/controllers/opro/oauth/auth_controller.rb
|
174
|
+
- app/controllers/opro/oauth/client_app_controller.rb
|
175
|
+
- app/controllers/opro/oauth/docs_controller.rb
|
176
|
+
- app/controllers/opro/oauth/tests_controller.rb
|
177
|
+
- app/controllers/opro/oauth/token_controller.rb
|
178
178
|
- app/controllers/opro_controller.rb
|
179
|
-
- app/models/oauth/
|
180
|
-
- app/models/oauth/client_app.rb
|
181
|
-
- app/views/oauth/auth/new.html.erb
|
182
|
-
- app/views/oauth/client_app/create.html.erb
|
183
|
-
- app/views/oauth/client_app/index.html.erb
|
184
|
-
- app/views/oauth/client_app/new.html.erb
|
185
|
-
- app/views/oauth/docs/index.html.erb
|
186
|
-
- app/views/oauth/docs/markdown/curl.md.erb
|
187
|
-
- app/views/oauth/docs/markdown/oauth.md.erb
|
188
|
-
- app/views/oauth/docs/markdown/permissions.md.erb
|
189
|
-
- app/views/oauth/docs/markdown/quick_start.md.erb
|
190
|
-
- app/views/oauth/docs/markdown/refresh_tokens.md.erb
|
191
|
-
- app/views/oauth/docs/show.html.erb
|
192
|
-
- app/views/oauth/tests/index.html.erb
|
179
|
+
- app/models/opro/oauth/auth_grant.rb
|
180
|
+
- app/models/opro/oauth/client_app.rb
|
181
|
+
- app/views/opro/oauth/auth/new.html.erb
|
182
|
+
- app/views/opro/oauth/client_app/create.html.erb
|
183
|
+
- app/views/opro/oauth/client_app/index.html.erb
|
184
|
+
- app/views/opro/oauth/client_app/new.html.erb
|
185
|
+
- app/views/opro/oauth/docs/index.html.erb
|
186
|
+
- app/views/opro/oauth/docs/markdown/curl.md.erb
|
187
|
+
- app/views/opro/oauth/docs/markdown/oauth.md.erb
|
188
|
+
- app/views/opro/oauth/docs/markdown/permissions.md.erb
|
189
|
+
- app/views/opro/oauth/docs/markdown/quick_start.md.erb
|
190
|
+
- app/views/opro/oauth/docs/markdown/refresh_tokens.md.erb
|
191
|
+
- app/views/opro/oauth/docs/show.html.erb
|
192
|
+
- app/views/opro/oauth/tests/index.html.erb
|
193
193
|
- config/routes.rb
|
194
194
|
- lib/generators/active_record/opro_generator.rb
|
195
|
-
- lib/generators/active_record/templates/
|
196
|
-
- lib/generators/active_record/templates/
|
195
|
+
- lib/generators/active_record/templates/auth_grants.rb
|
196
|
+
- lib/generators/active_record/templates/client_apps.rb
|
197
197
|
- lib/generators/opro/install_generator.rb
|
198
198
|
- lib/generators/templates/opro.rb
|
199
199
|
- lib/opro.rb
|
@@ -233,8 +233,8 @@ files:
|
|
233
233
|
- test/dummy/config/locales/en.yml
|
234
234
|
- test/dummy/config/routes.rb
|
235
235
|
- test/dummy/db/migrate/20120408163038_devise_create_users.rb
|
236
|
-
- test/dummy/db/migrate/
|
237
|
-
- test/dummy/db/migrate/
|
236
|
+
- test/dummy/db/migrate/20120618085751_create_opro_auth_grants.rb
|
237
|
+
- test/dummy/db/migrate/20120618085752_create_opro_client_apps.rb
|
238
238
|
- test/dummy/db/schema.rb
|
239
239
|
- test/dummy/public/404.html
|
240
240
|
- test/dummy/public/422.html
|
@@ -274,7 +274,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
274
|
version: '0'
|
275
275
|
segments:
|
276
276
|
- 0
|
277
|
-
hash: -
|
277
|
+
hash: -4287808992153183066
|
278
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
279
|
none: false
|
280
280
|
requirements:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class Oauth::ClientAppController < OproController
|
2
|
-
before_filter :opro_authenticate_user!
|
3
|
-
|
4
|
-
def new
|
5
|
-
@client_app = Oauth::ClientApp.new
|
6
|
-
end
|
7
|
-
|
8
|
-
# Show all client applications belonging to the current user
|
9
|
-
def index
|
10
|
-
@client_apps = Oauth::ClientApp.where(:user_id => current_user.id)
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
def create
|
15
|
-
@client_app = Oauth::ClientApp.find_by_user_id_and_name(current_user.id, params[:oauth_client_app][:name])
|
16
|
-
@client_app ||= Oauth::ClientApp.create_with_user_and_name(current_user, params[:oauth_client_app][:name])
|
17
|
-
if @client_app.save
|
18
|
-
# do nothing
|
19
|
-
else
|
20
|
-
render :new
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|