warden-googleapps-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +91 -0
- data/Rakefile +1 -0
- data/lib/warden-googleapps-rails.rb +5 -0
- data/lib/warden/googleapps/rails.rb +33 -0
- data/lib/warden/googleapps/rails/config.rb +12 -0
- data/lib/warden/googleapps/rails/controller_helpers.rb +31 -0
- data/lib/warden/googleapps/rails/railtie.rb +34 -0
- data/lib/warden/googleapps/rails/routes.rb +38 -0
- data/lib/warden/googleapps/rails/version.rb +7 -0
- data/warden-googleapps-rails.gemspec +24 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00e45fe8577aa2c29df7ddd01ba91f327dbf0385
|
4
|
+
data.tar.gz: 73092eb605ffbb9808f1c28d7271c04e21f2700b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 538f7956687bd0311e456ac664ff3f6de97ed357850ef9fba7c145603778c8989c9aeeee76b87832f1dbee60c6417cedf4960c9cba1374bec722c66d06365381
|
7
|
+
data.tar.gz: c1c7f9aef664021bae1b874d723722e2e83a25cf08ba6109ebde2799fbe2533c2a9236b46ba6307e3db5a26384978abde59c837c4782000552c10fb90ab201a7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Richard Lee
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# warden-googleapps-rails
|
2
|
+
|
3
|
+
A simple Rails integration using Google Apps OAuth.
|
4
|
+
|
5
|
+
It's built on [warden-googleapps](https://github.com/atoms/warden-googleapps), and heavily inspired by [warden-github-rails](https://github.com/fphilipe/warden-github-rails).
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
`warden-googleapps-rails` provides both controller-based and router-based authentication methods for Rails apps.
|
10
|
+
|
11
|
+
First of all, you need to configure this gem by creating an initializer like `config/initializers/warden_googleapps_rails.rb`, and include:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
Warden::GoogleApps::Rails.setup do |config|
|
15
|
+
# Required
|
16
|
+
config.google_apps_domain = "example.org"
|
17
|
+
|
18
|
+
# Optional
|
19
|
+
# config.google_apps_endpoint = "http://www.google.com/accounts/o8/id" # this is gmail
|
20
|
+
# config.google_apps_redirect_url = "http://example.org/verify_url" # endpoint where google apps redirects to after successful authentication
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
### Controller Helpers
|
25
|
+
|
26
|
+
There're several authentication methods for controllers.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# Redirect user to Google Apps OAuth if user not log in
|
30
|
+
googleapps_authenticate!
|
31
|
+
|
32
|
+
# Return whether user has logged in
|
33
|
+
googleapps_authenticate?
|
34
|
+
|
35
|
+
# Get user object
|
36
|
+
googleapps_user
|
37
|
+
|
38
|
+
# Log out
|
39
|
+
googleapps_logout
|
40
|
+
```
|
41
|
+
|
42
|
+
Thus you could write something like:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class PostsController < ApplicationController
|
46
|
+
# Ask user log in for all actions
|
47
|
+
before_filter :googleapps_authenticate!
|
48
|
+
|
49
|
+
def new
|
50
|
+
@user = googleapps_user
|
51
|
+
# …
|
52
|
+
end
|
53
|
+
# …
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
### Router Constraints
|
58
|
+
|
59
|
+
In your `routes.rb` you could simply wrap your resources:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
MyApp::Application.routes.draw do
|
63
|
+
# …
|
64
|
+
|
65
|
+
namespace :admin do do
|
66
|
+
# Initialize Google Apps authentication flow if user not log in
|
67
|
+
googleapps_authenticate do
|
68
|
+
resources :posts
|
69
|
+
end
|
70
|
+
|
71
|
+
# Require user log in but will not redirect to OAuth flow
|
72
|
+
googleapps_authenticated do
|
73
|
+
resources :users
|
74
|
+
end
|
75
|
+
# …
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
## Contact
|
82
|
+
|
83
|
+
Richard Lee
|
84
|
+
|
85
|
+
- http://github.com/dlackty
|
86
|
+
- http://twitter.com/dlackty
|
87
|
+
- dlackty@gmail.com
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
`warden-googleapps-rails` is available under the MIT license. See the `LICENSE.txt` file for more info.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
require "warden/googleapps/rails/config"
|
4
|
+
require "warden/googleapps/rails/controller_helpers"
|
5
|
+
require "warden/googleapps/rails/railtie"
|
6
|
+
require "warden/googleapps/rails/routes"
|
7
|
+
|
8
|
+
module Warden
|
9
|
+
module GoogleApps
|
10
|
+
module Rails
|
11
|
+
extend SingleForwardable
|
12
|
+
|
13
|
+
def_delegators :config,
|
14
|
+
:google_apps_domain,
|
15
|
+
:google_apps_endpoint,
|
16
|
+
:google_apps_redirect_url
|
17
|
+
|
18
|
+
@config = Config.new
|
19
|
+
|
20
|
+
def self.google_apps_domain
|
21
|
+
self.config.google_apps_domain
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.config
|
25
|
+
@config
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.setup
|
29
|
+
yield config
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Warden
|
2
|
+
module GoogleApps
|
3
|
+
module Rails
|
4
|
+
module ControllerHelpers
|
5
|
+
def self.included(klass)
|
6
|
+
klass.helper_method(:googleapps_authenticated?, :googleapps_user)
|
7
|
+
end
|
8
|
+
|
9
|
+
def googleapps_authenticate!
|
10
|
+
request.env['warden'].authenticate!
|
11
|
+
end
|
12
|
+
|
13
|
+
def googleapps_logout
|
14
|
+
request.env['warden'].logout
|
15
|
+
end
|
16
|
+
|
17
|
+
def googleapps_authenticated?
|
18
|
+
request.env['warden'].authenticated?
|
19
|
+
end
|
20
|
+
|
21
|
+
def googleapps_user
|
22
|
+
request.env['warden'].user
|
23
|
+
end
|
24
|
+
|
25
|
+
def googleapps_session
|
26
|
+
request.env['warden'].session if googleapps_authenticated?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Warden
|
2
|
+
module GoogleApps
|
3
|
+
module Rails
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer 'warden-googleapps-rails.warden' do |app|
|
6
|
+
app.config.middleware.use Warden::Manager do |config|
|
7
|
+
setup_default_strategies(config)
|
8
|
+
setup_failure_app(config)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer 'warden-googleapps-rails.helpers' do
|
13
|
+
ActiveSupport.on_load(:action_controller) do
|
14
|
+
include ControllerHelpers
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup_default_strategies(config)
|
19
|
+
config.default_strategies :google_apps
|
20
|
+
fail StandardError, "No Google Apps domain specified." if Rails.google_apps_domain.nil?
|
21
|
+
config[:google_apps_domain] = Rails.google_apps_domain
|
22
|
+
config[:google_apps_endpoint] = Rails.google_apps_endpoint
|
23
|
+
config[:google_apps_redirect_url] = Rails.google_apps_redirect_url
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup_failure_app(config)
|
27
|
+
config.failure_app = lambda do |env|
|
28
|
+
[403, {}, [env['warden'].message]]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Warden
|
2
|
+
module GoogleApps
|
3
|
+
module Rails
|
4
|
+
module Routes
|
5
|
+
def googleapps_authenticate(&routes_block)
|
6
|
+
googleapps_constraint(routes_block) do |warden|
|
7
|
+
warden.authenticate!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def googleapps_authenticated(&routes_block)
|
12
|
+
googleapps_constraint(routes_block) do |warden|
|
13
|
+
warden.authenticate?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def googleapps_unauthenticated(&routes_block)
|
18
|
+
googleapps_constraint(routes_block) do |warden|
|
19
|
+
not warden.authenticated?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def googleapps_constraint(routes_block, &block)
|
26
|
+
constraint = lambda do |request|
|
27
|
+
warden = request.env['warden']
|
28
|
+
block.call(warden)
|
29
|
+
end
|
30
|
+
|
31
|
+
constraints(constraint, &routes_block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ActionDispatch::Routing::Mapper.send(:include, Warden::GoogleApps::Rails::Routes)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'warden/googleapps/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "warden-googleapps-rails"
|
8
|
+
spec.version = Warden::GoogleApps::Rails::VERSION
|
9
|
+
spec.authors = ["Richard Lee"]
|
10
|
+
spec.email = ["dlackty@gmail.com"]
|
11
|
+
spec.summary = %q{Simple integration for Rails to use Google Apps authentication.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/dlackty/warden-googleapps-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency 'rspec', '~> 2.12'
|
21
|
+
|
22
|
+
spec.add_dependency 'warden-googleapps', '~> 0.1.4'
|
23
|
+
spec.add_dependency 'railties', '>= 3.1'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: warden-googleapps-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Richard Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: warden-googleapps
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
description: Simple integration for Rails to use Google Apps authentication.
|
56
|
+
email:
|
57
|
+
- dlackty@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/warden-googleapps-rails.rb
|
68
|
+
- lib/warden/googleapps/rails.rb
|
69
|
+
- lib/warden/googleapps/rails/config.rb
|
70
|
+
- lib/warden/googleapps/rails/controller_helpers.rb
|
71
|
+
- lib/warden/googleapps/rails/railtie.rb
|
72
|
+
- lib/warden/googleapps/rails/routes.rb
|
73
|
+
- lib/warden/googleapps/rails/version.rb
|
74
|
+
- warden-googleapps-rails.gemspec
|
75
|
+
homepage: https://github.com/dlackty/warden-googleapps-rails
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.3
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Simple integration for Rails to use Google Apps authentication.
|
99
|
+
test_files: []
|