rack-oauth2-server 1.0.beta

Sign up to get free protection for your applications and to get access to all the features.
data/test/setup.rb ADDED
@@ -0,0 +1,73 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+ require "test/unit"
4
+ require "rack/test"
5
+ require "shoulda"
6
+ require "ap"
7
+ require "json"
8
+ $: << File.dirname(__FILE__) + "/../lib"
9
+ require "rack/oauth2/server"
10
+
11
+
12
+ ENV["RACK_ENV"] = "test"
13
+ DATABASE = Mongo::Connection.new["rack_test"]
14
+ FRAMEWORK = ENV["FRAMEWORK"] || "sinatra"
15
+
16
+
17
+ case FRAMEWORK
18
+ when "sinatra", nil
19
+
20
+ require "sinatra/base"
21
+ puts "Testing with Sinatra #{Sinatra::VERSION}"
22
+ require File.dirname(__FILE__) + "/sinatra/my_app"
23
+
24
+ class Test::Unit::TestCase
25
+ def app
26
+ MyApp.new
27
+ end
28
+ end
29
+
30
+ when "rails2"
31
+
32
+ require "initializer"
33
+ require "action_controller"
34
+ RAILS_ROOT = File.dirname(__FILE__) + "/rails"
35
+ RAILS_ENV = "test"
36
+
37
+ class << Rails
38
+ def vendor_rails?
39
+ false
40
+ end
41
+ end
42
+ require RAILS_ROOT + "/config/environment"
43
+ puts "Testing with Rails #{Rails.version}"
44
+
45
+ class Test::Unit::TestCase
46
+ def app
47
+ ActionController::Dispatcher.new
48
+ end
49
+ end
50
+
51
+ else
52
+ puts "Unknown framework #{FRAMEWORK}"
53
+ exit -1
54
+ end
55
+
56
+
57
+ class Test::Unit::TestCase
58
+ include Rack::Test::Methods
59
+
60
+ def setup
61
+ Rack::OAuth2::Server.database = DATABASE
62
+ @client = Rack::OAuth2::Server::Client.create(:display_name=>"UberClient", :redirect_uri=>"http://uberclient.dot/callback")
63
+ end
64
+
65
+ attr_reader :client, :end_user
66
+
67
+ def teardown
68
+ Rack::OAuth2::Server::Client.collection.drop
69
+ Rack::OAuth2::Server::AuthRequest.collection.drop
70
+ Rack::OAuth2::Server::AccessGrant.collection.drop
71
+ Rack::OAuth2::Server::AccessToken.collection.drop
72
+ end
73
+ end
@@ -0,0 +1,67 @@
1
+ require "rack/oauth2/sinatra"
2
+
3
+ class MyApp < Sinatra::Base
4
+ use Rack::Logger
5
+ set :sessions, true
6
+
7
+ register Rack::OAuth2::Sinatra
8
+ oauth[:scopes] = %w{read write}
9
+ oauth[:authenticator] = lambda do |username, password|
10
+ "Superman" if username == "cowbell" && password == "more"
11
+ end
12
+ oauth[:database] = DATABASE
13
+
14
+
15
+ # 3. Obtaining End-User Authorization
16
+
17
+ get "/oauth/authorize" do
18
+ session["oauth.authorization"] = oauth.authorization
19
+ "client: #{oauth.client.display_name}\nscope: #{oauth.scope.join(", ")}"
20
+ end
21
+
22
+ post "/oauth/grant" do
23
+ oauth.grant! session["oauth.authorization"], "Superman"
24
+ end
25
+
26
+ post "/oauth/deny" do
27
+ oauth.deny! session["oauth.authorization"]
28
+ end
29
+
30
+
31
+ # 5. Accessing a Protected Resource
32
+
33
+ before { @user = oauth.resource if oauth.authenticated? }
34
+
35
+ get "/public" do
36
+ if oauth.authenticated?
37
+ "HAI from #{oauth.resource}"
38
+ else
39
+ "HAI"
40
+ end
41
+ end
42
+
43
+ oauth_required "/private", "/change"
44
+
45
+ get "/private" do
46
+ "Shhhh"
47
+ end
48
+
49
+ post "/change" do
50
+ "Woot!"
51
+ end
52
+
53
+ oauth_required "/calc", :scope=>"math"
54
+
55
+ get "/calc" do
56
+ end
57
+
58
+ get "/user" do
59
+ @user
60
+ end
61
+
62
+ get "/list_tokens" do
63
+ oauth.list_access_tokens("Superman").map(&:token).join(" ")
64
+ end
65
+
66
+ end
67
+
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-oauth2-server
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31098137
5
+ prerelease: true
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - beta
10
+ version: 1.0.beta
11
+ platform: ruby
12
+ authors:
13
+ - Assaf Arkin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-02 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 1
32
+ version: "1"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: mongo
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 1
44
+ segments:
45
+ - 1
46
+ version: "1"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: bson_ext
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: Because you don't allow strangers into your app, and OAuth 2.0 is the new awesome.
64
+ email: assaf@labnotes.org
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - README.rdoc
71
+ - CHANGELOG
72
+ files:
73
+ - lib/rack/oauth2/models/access_grant.rb
74
+ - lib/rack/oauth2/models/access_token.rb
75
+ - lib/rack/oauth2/models/auth_request.rb
76
+ - lib/rack/oauth2/models/client.rb
77
+ - lib/rack/oauth2/models.rb
78
+ - lib/rack/oauth2/rails.rb
79
+ - lib/rack/oauth2/server/errors.rb
80
+ - lib/rack/oauth2/server/helper.rb
81
+ - lib/rack/oauth2/server/utils.rb
82
+ - lib/rack/oauth2/server/version.rb
83
+ - lib/rack/oauth2/server.rb
84
+ - lib/rack/oauth2/sinatra.rb
85
+ - lib/rack-oauth2-server.rb
86
+ - test/access_grant_test.rb
87
+ - test/access_token_test.rb
88
+ - test/authorization_test.rb
89
+ - test/rails/app/controllers/api_controller.rb
90
+ - test/rails/app/controllers/application_controller.rb
91
+ - test/rails/app/controllers/oauth_controller.rb
92
+ - test/rails/config/environment.rb
93
+ - test/rails/config/environments/test.rb
94
+ - test/rails/config/routes.rb
95
+ - test/rails/log/test.log
96
+ - test/setup.rb
97
+ - test/sinatra/my_app.rb
98
+ - CHANGELOG
99
+ - MIT-LICENSE
100
+ - README.rdoc
101
+ - Rakefile
102
+ - Gemfile
103
+ - rack-oauth2-server.gemspec
104
+ has_rdoc: true
105
+ homepage: http://github.com/assaf/rack-oauth2-server
106
+ licenses: []
107
+
108
+ post_install_message: ""
109
+ rdoc_options:
110
+ - --title
111
+ - rack-oauth2-server 1.0.beta
112
+ - --main
113
+ - README.rdoc
114
+ - --webcvs
115
+ - http://github.com/assaf/rack-oauth2-server
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 57
124
+ segments:
125
+ - 1
126
+ - 8
127
+ - 7
128
+ version: 1.8.7
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">"
133
+ - !ruby/object:Gem::Version
134
+ hash: 25
135
+ segments:
136
+ - 1
137
+ - 3
138
+ - 1
139
+ version: 1.3.1
140
+ requirements: []
141
+
142
+ rubyforge_project:
143
+ rubygems_version: 1.3.7
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: OAuth 2.0 Authorization Server as a Rack module
147
+ test_files: []
148
+