sinatra-g_auth 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -5
- data/lib/sinatra/g_auth.rb +1 -1
- data/lib/sinatra/g_auth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c16292e30405a43d9d800e9a71407d9e2b8a0033
|
4
|
+
data.tar.gz: cd44f54d65d74c15becf347afe272fcc03b80e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84027e93975844fbe898990bd1653f9757cac08da08f56bc9cd1689419f6482b97c99ece98848638dd3bd338dcc9349252f98d689588cba858d0d3276d828e94
|
7
|
+
data.tar.gz: 916fc25bb7e4968b4ade146b416404e0c512ad079a510bee752c2706bdd3c1b36b491fbf60f961b63e65fb564c14639814f1c23434a7f6f6b2325c5bf32eeca1
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# Sinatra::GAuth
|
2
2
|
|
3
|
-
|
3
|
+
Quickly add Google Apps authentication to any Sintra app.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem '
|
9
|
+
gem 'sinatra-g_auth', require: 'sinatra/g_auth'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -14,11 +14,66 @@ And then execute:
|
|
14
14
|
|
15
15
|
Or install it yourself as:
|
16
16
|
|
17
|
-
$ gem install
|
17
|
+
$ gem install sinatra-g_auth
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Configure the settings and register the extension to get up and running.
|
22
|
+
|
23
|
+
````ruby
|
24
|
+
class App < Sinatra::Base
|
25
|
+
set :gauth_domain, 'example.org' # set this to your google apps domain
|
26
|
+
set :gauth_tmp_dir, './tmp' # path to a directory that's writable by your web process
|
27
|
+
set :gauth_redirect, '/' # where to redirect users after they've authenticated
|
28
|
+
register Sinatra::GAuth # add the sinatra extension to your stack
|
29
|
+
|
30
|
+
get '/protected' do
|
31
|
+
protect_with_gauth! # add this to any route you want protected
|
32
|
+
# ...
|
33
|
+
end
|
34
|
+
end
|
35
|
+
````
|
36
|
+
|
37
|
+
Once the user has authenticated with google, some basic information is added to the session:
|
38
|
+
|
39
|
+
````ruby
|
40
|
+
session[:_gauth][:id] # => google ID
|
41
|
+
session[:_gauth][:name] # => user's full name
|
42
|
+
session[:_gauth][:email] # => google apps email address
|
43
|
+
````
|
44
|
+
|
45
|
+
If attempting to add `protect_with_gauth!` to a before filter, be sure to skip paths that begin with `/auth`:
|
46
|
+
|
47
|
+
````ruby
|
48
|
+
before(%r{^(?!(\/auth))}) do
|
49
|
+
protect_with_gauth!
|
50
|
+
end
|
51
|
+
````
|
52
|
+
|
53
|
+
This extension will enable sessions, but does not configure a session store. Do that with the middleware of your choice (e.g. `Rack::Session::Cookie`, `Rack::Session::Dalli`, etc).
|
54
|
+
|
55
|
+
Authentication is automatic for any routes that call `protect_with_gauth!`. You can add a more user friendly login page, like this:
|
56
|
+
|
57
|
+
````ruby
|
58
|
+
get '/login' do
|
59
|
+
'<a href="/auth/g">Login with Google Apps</a>'
|
60
|
+
end
|
61
|
+
````
|
62
|
+
|
63
|
+
This extension does not provide a logout mechanism, but one can be added easily if you like:
|
64
|
+
|
65
|
+
````ruby
|
66
|
+
get '/logout' do
|
67
|
+
session.clear
|
68
|
+
# redirect or whatever...
|
69
|
+
end
|
70
|
+
````
|
71
|
+
|
72
|
+
## Project Status
|
73
|
+
|
74
|
+
- Build: [![Build Status](https://secure.travis-ci.org/styleseek/sinatra-g_auth.png?branch=master)](https://travis-ci.org/styleseek/sinatra-g_auth)
|
75
|
+
- Code Quality: [![Code Climate](https://codeclimate.com/github/styleseek/sinatra-g_auth.png)](https://codeclimate.com/github/styleseek/sinatra-g_auth)
|
76
|
+
- Dependencies: [![Dependency Status](https://gemnasium.com/styleseek/sinatra-g_auth.png)](https://gemnasium.com/styleseek/sinatra-g_auth)
|
22
77
|
|
23
78
|
## Contributing
|
24
79
|
|
data/lib/sinatra/g_auth.rb
CHANGED