sinatra-google-auth 0.0.1 → 0.0.2

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # Sinatra::Google::Auth
2
2
 
3
- TODO: Write a gem description
3
+ Drop
4
+
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,7 +19,40 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ The gem exposes a single `authenticate` helper that protects the endpoint with
23
+ Google OpenID authentication.
24
+
25
+ ### Classic-Style Apps
26
+
27
+ ```ruby
28
+ require 'sinatra/base
29
+ require 'sinatra/google-auth'
30
+
31
+ get '*' do
32
+ authenticate
33
+ 'hello'
34
+ end
35
+ ```
36
+
37
+
38
+ ### Modular Apps
39
+
40
+ ```ruby
41
+ require 'sinatra/base
42
+ require 'sinatra/google-auth'
43
+
44
+ class App < Sinatra::Base
45
+ register Sinatra::GoogleAuth
46
+
47
+ get '*' do
48
+ authenticate
49
+ 'hello'
50
+ end
51
+ end
52
+ ```
53
+
54
+
55
+
22
56
 
23
57
  ## Contributing
24
58
 
@@ -0,0 +1 @@
1
+ require 'sinatra/google-auth'
@@ -0,0 +1,40 @@
1
+ require 'omniauth-openid'
2
+
3
+ module Sinatra
4
+ module GoogleAuth
5
+
6
+ module Helpers
7
+ def authenticate
8
+ unless session["user"]
9
+ redirect to "/auth/google"
10
+ end
11
+ end
12
+
13
+ def handle_authentication_callback
14
+ unless session["user"]
15
+ user_info = request.env["omniauth.auth"].info
16
+ session["user"] = Array(user_info.email).first.downcase
17
+ end
18
+
19
+ redirect to "/"
20
+ end
21
+ end
22
+
23
+ def self.registered(app)
24
+ app.helpers GoogleAuth::Helpers
25
+ app.use ::Rack::Session::Cookie, :secret => ENV['SESSION_SECRET'] || SecureRandom.hex(64)
26
+ app.use ::OmniAuth::Strategies::OpenID, :name => "google", :identifier => "http://heroku.com/openid"
27
+
28
+ app.get "/auth/:provider/callback" do
29
+ handle_authentication_callback
30
+ end
31
+
32
+ app.post "/auth/:provider/callback" do
33
+ handle_authentication_callback
34
+ end
35
+ end
36
+ end
37
+
38
+ register GoogleAuth
39
+ end
40
+
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module GoogleAuth
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -23,6 +23,8 @@ files:
23
23
  - LICENSE
24
24
  - README.md
25
25
  - Rakefile
26
+ - lib/sinatra-google-auth.rb
27
+ - lib/sinatra/google-auth.rb
26
28
  - lib/sinatra/google-auth/version.rb
27
29
  - lib/sinatra/gooogle-auth.rb
28
30
  - sinatra-google-auth.gemspec