sinatra-google-auth 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,6 +21,25 @@ Or install it yourself as:
21
21
  The gem exposes a single `authenticate` helper that protects the endpoint with
22
22
  Google OpenID authentication.
23
23
 
24
+ As of version 0.0.7. you can also use `Sinatra::GoogleAuth::Middleware` to protect your whole app
25
+ and/or control where the authentication happens in a middleware chain.
26
+
27
+ ### Middleware
28
+
29
+ ```ruby
30
+ require 'sinatra/base'
31
+ require 'sinatra/google-auth'
32
+
33
+ class App < Sinatra::Base
34
+ register Sinatra::GoogleAuth
35
+ use Sinatra::GoogleAuth::Middleware
36
+
37
+ get '*' do
38
+ 'hello'
39
+ end
40
+ end
41
+ ```
42
+
24
43
  ### Classic-Style Apps
25
44
 
26
45
  ```ruby
@@ -33,7 +52,6 @@ get '*' do
33
52
  end
34
53
  ```
35
54
 
36
-
37
55
  ### Modular Apps
38
56
 
39
57
  ```ruby
@@ -69,7 +87,7 @@ class App < Sinatra::Base
69
87
  end
70
88
  ```
71
89
 
72
- ## Configuration
90
+ ## Configuration
73
91
 
74
92
  ### Google Endpoint
75
93
 
@@ -77,7 +95,7 @@ Configure your Google OpenID endpoint via setting the ENV var `GOOGLE_AUTH_URL`
77
95
 
78
96
  $ export GOOGLE_AUTH_URL=http://myurl.com/openid
79
97
 
80
- or before requiring
98
+ or before requiring
81
99
 
82
100
  ```ruby
83
101
  ENV['GOOGLE_AUTH_URL'] = 'http://myurl.com/openid'
@@ -86,7 +104,7 @@ require 'sinatra'
86
104
  require 'sinatra/google-auth'
87
105
  ```
88
106
 
89
- ### Session Secret
107
+ ### Session Secret
90
108
 
91
109
  Configure your session secret by setting `SESSION_SECRET` or `SECURE_KEY` ENV vars.
92
110
 
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module GoogleAuth
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
@@ -3,6 +3,21 @@ require 'omniauth-openid'
3
3
  module Sinatra
4
4
  module GoogleAuth
5
5
 
6
+ class Middleware
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ if env['rack.session']["user"] || ENV['REQUEST_PATH'] == '/auth/google/callback'
13
+ @app.call(env)
14
+ else
15
+ env['rack.session']['google-auth-redirect'] = ENV['REQUEST_PATH']
16
+ return [301, {'Content-Type' => 'text/html', 'Location' => '/auth/google'}, []]
17
+ end
18
+ end
19
+ end
20
+
6
21
  module Helpers
7
22
  def authenticate
8
23
  unless session["user"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-google-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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-01 00:00:00.000000000Z
12
+ date: 2012-06-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-openid
16
- requirement: &70096299813860 !ruby/object:Gem::Requirement
16
+ requirement: &70197566972620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70096299813860
24
+ version_requirements: *70197566972620
25
25
  description: Drop-in google auth for sinatra apps
26
26
  email:
27
27
  - christopher.continanza@gmail.com