stagehand 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -3
- data/lib/stagehand.rb +22 -14
- data/lib/stagehand/client.rb +7 -0
- data/lib/stagehand/client/oauth.rb +32 -0
- data/lib/stagehand/client/user.rb +10 -0
- data/lib/stagehand/rack/middleware.rb +33 -0
- data/lib/stagehand/railtie.rb +5 -0
- data/lib/stagehand/version.rb +1 -1
- data/spec/stagehand_spec.rb +36 -7
- data/stagehand.gemspec +1 -0
- metadata +22 -7
data/README.md
CHANGED
@@ -7,9 +7,9 @@ Usage
|
|
7
7
|
=====
|
8
8
|
|
9
9
|
YourApp::Application.configure do
|
10
|
-
config.stagehand.client_id = 'YOUR_APP_CLIENT_ID'
|
11
|
-
config.stagehand.client_secret = 'YOUR_APP_CLIENT_SECRET'
|
12
|
-
config.stagehand.resource_host = 'YOUR_APP_RESOURCE_HOST'
|
10
|
+
config.stagehand.client_id = 'YOUR_APP_CLIENT_ID'
|
11
|
+
config.stagehand.client_secret = 'YOUR_APP_CLIENT_SECRET'
|
12
|
+
config.stagehand.resource_host = 'YOUR_APP_RESOURCE_HOST'
|
13
13
|
config.stagehand.client_host = 'YOUR_APP_HOST_WITH_PORT'
|
14
14
|
end
|
15
15
|
|
data/lib/stagehand.rb
CHANGED
@@ -1,25 +1,33 @@
|
|
1
|
-
require '
|
2
|
-
require 'stagehand/
|
1
|
+
require 'httparty'
|
2
|
+
require 'stagehand/client'
|
3
|
+
require 'stagehand/rack/middleware'
|
3
4
|
require 'stagehand/railtie' if defined? ::Rails::Railtie
|
5
|
+
require 'stagehand/version'
|
6
|
+
require 'yajl'
|
4
7
|
|
5
8
|
module Stagehand
|
6
9
|
class Config
|
7
10
|
attr_accessor :client_id, :client_secret, :client_host, :resource_host
|
8
11
|
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def self.configure
|
15
|
-
yield self.config
|
16
|
-
end
|
13
|
+
class << self
|
14
|
+
def config
|
15
|
+
@@config ||= Config.new
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def configure
|
19
|
+
yield self.config
|
20
|
+
end
|
21
|
+
|
22
|
+
# return Stagehand::Client
|
23
|
+
def new(options={})
|
24
|
+
Stagehand::Client.new(options)
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
# Delegate to Stagehand::Client
|
28
|
+
def method_missing(method, *args, &block)
|
29
|
+
return super unless new.respond_to?(method)
|
30
|
+
new.send(method, *args, &block)
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Stagehand
|
2
|
+
class Client
|
3
|
+
# Methods for OAuth 2.0 authentication
|
4
|
+
module OAuth
|
5
|
+
# URL used for initial OAuth login and authorization
|
6
|
+
def authorize_url
|
7
|
+
Stagehand.config.resource_host + "/oauth/authorize?client_id=#{Stagehand.config.client_id}&client_secret=#{Stagehand.config.client_secret}&redirect_uri=#{Stagehand.config.client_host}/callback"
|
8
|
+
end
|
9
|
+
|
10
|
+
def access_token_url
|
11
|
+
Stagehand.config.resource_host + "/oauth/access_token"
|
12
|
+
end
|
13
|
+
|
14
|
+
def redirect_uri
|
15
|
+
Stagehand.config.client_host + "/callback"
|
16
|
+
end
|
17
|
+
|
18
|
+
def logout_url
|
19
|
+
Stagehand.config.resource_host + "/logout?redirect_uri=#{Stagehand.config.client_host}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def access_token
|
23
|
+
request.env['rack.session'][:access_token]
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_with_access_token(path, params)
|
27
|
+
params[:oauth_token] = access_token
|
28
|
+
HTTParty.get(Stagehand.config.resource_host + path, query: params)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Stagehand::Rack
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
request = env['stagehand'] = Rack::Request.new(env)
|
9
|
+
|
10
|
+
response = catch :stagehand do
|
11
|
+
if request.path == '/callback'
|
12
|
+
token_response = HTTParty.post(Stagehand.access_token_url, :body => {
|
13
|
+
:client_id => Stagehand.config.client_id,
|
14
|
+
:client_secret => Stagehand.config.client_secret,
|
15
|
+
:redirect_uri => Stagehand.redirect_uri,
|
16
|
+
:code => request.params['code'],
|
17
|
+
:grant_type => 'authorization_code'}
|
18
|
+
)
|
19
|
+
env['rack.session'][:access_token] = token_response["access_token"]
|
20
|
+
# redirect to root
|
21
|
+
[302, {'Location'=>'/'}, []]
|
22
|
+
else
|
23
|
+
@app.call(env)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue InvalidRequest => e
|
27
|
+
[400, {}, e.message]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class InvalidRequest < StandardError
|
32
|
+
end
|
33
|
+
end
|
data/lib/stagehand/railtie.rb
CHANGED
data/lib/stagehand/version.rb
CHANGED
data/spec/stagehand_spec.rb
CHANGED
@@ -1,15 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
RSpec.configure do |c|
|
4
|
+
c.before(:each) do
|
5
|
+
Stagehand.configure do |config|
|
6
|
+
config.client_id = 'test_app'
|
7
|
+
config.client_secret = 'abcdef123456'
|
8
|
+
config.resource_host = 'http://0.0.0.0:3000'
|
9
|
+
config.client_host = 'http://0.0.0.0:4000'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
describe Stagehand do
|
4
15
|
describe "initialization" do
|
5
|
-
it "
|
6
|
-
Stagehand.configure do |config|
|
7
|
-
config.client_id = 'test_app'
|
8
|
-
config.client_secret = 'abcdef123456'
|
9
|
-
config.resource_host = 'http://0.0.0.0:3000'
|
10
|
-
config.client_host = 'http://0.0.0.0:4000'
|
11
|
-
end
|
16
|
+
it "can create an OAuth 2.0 authorize url" do
|
12
17
|
Stagehand.authorize_url.should == "http://0.0.0.0:3000/oauth/authorize?client_id=test_app&client_secret=abcdef123456&redirect_uri=http://0.0.0.0:4000/callback"
|
13
18
|
end
|
14
19
|
end
|
20
|
+
|
21
|
+
describe "url helpers" do
|
22
|
+
it "can get the access token url" do
|
23
|
+
Stagehand.access_token_url.should == "http://0.0.0.0:3000/oauth/access_token"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can get the redirect uri" do
|
27
|
+
Stagehand.redirect_uri.should == "http://0.0.0.0:4000/callback"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can get the logout url" do
|
31
|
+
Stagehand.logout_url.should == "http://0.0.0.0:3000/logout?redirect_uri=http://0.0.0.0:4000"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can get the access token" do
|
35
|
+
Stagehand.access_token == session[:access_token]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "current user" do
|
40
|
+
it "can see his profile" do
|
41
|
+
Stagehand.profile == { username: "Test" }
|
42
|
+
end
|
43
|
+
end
|
15
44
|
end
|
data/stagehand.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stagehand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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: 2011-10-
|
12
|
+
date: 2011-10-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &88349500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.7.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *88349500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: yajl-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &88349180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *88349180
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: httparty
|
38
|
+
requirement: &88348780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.8.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *88348780
|
36
47
|
description: Client-side library for manipulating RESTful resources provided by Personas,
|
37
48
|
a Rails + Backbone user managment service
|
38
49
|
email:
|
@@ -46,6 +57,10 @@ files:
|
|
46
57
|
- README.md
|
47
58
|
- Rakefile
|
48
59
|
- lib/stagehand.rb
|
60
|
+
- lib/stagehand/client.rb
|
61
|
+
- lib/stagehand/client/oauth.rb
|
62
|
+
- lib/stagehand/client/user.rb
|
63
|
+
- lib/stagehand/rack/middleware.rb
|
49
64
|
- lib/stagehand/railtie.rb
|
50
65
|
- lib/stagehand/version.rb
|
51
66
|
- spec/spec_helper.rb
|
@@ -71,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
86
|
version: '0'
|
72
87
|
requirements: []
|
73
88
|
rubyforge_project: stagehand
|
74
|
-
rubygems_version: 1.8.
|
89
|
+
rubygems_version: 1.8.10
|
75
90
|
signing_key:
|
76
91
|
specification_version: 3
|
77
92
|
summary: client library for Personas (user management) service
|