google_auth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +19 -0
- data/Rakefile +1 -0
- data/app/controllers/sessions_controller.rb +26 -0
- data/config/routes.rb +5 -0
- data/google_auth.gemspec +20 -0
- data/lib/google_auth.rb +28 -0
- data/lib/google_auth/controller.rb +23 -0
- data/lib/google_auth/engine.rb +19 -0
- data/lib/google_auth/version.rb +3 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# GoogleAuth
|
2
|
+
|
3
|
+
## What
|
4
|
+
|
5
|
+
GoogleAuth is a convenience wrapper around `omniauth-google-apps` that
|
6
|
+
makes a lot of assumptions, and requires less setup.
|
7
|
+
|
8
|
+
## How
|
9
|
+
|
10
|
+
# Gemfile
|
11
|
+
gem 'google_auth'
|
12
|
+
|
13
|
+
# config/initializers/google_auth.rb
|
14
|
+
Rails.application.config.google_auth.domain = 'yourgoogleappsdomain.com'
|
15
|
+
# other options: 'user_class', 'path'. See source for details.
|
16
|
+
|
17
|
+
# Whichever controller you want behind the login-wall
|
18
|
+
include GoogleAuth::Controller
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
skip_before_filter :ensure_authenticated
|
3
|
+
|
4
|
+
def new
|
5
|
+
redirect_to '/auth/g'
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
if auth = request.env['omniauth.auth']
|
10
|
+
user = User.find_or_initialize_by_email(auth['info']['email'])
|
11
|
+
user.uid = auth['uid']
|
12
|
+
user.name = auth['info']['name']
|
13
|
+
user.save!
|
14
|
+
|
15
|
+
session[:user_id] = user.id
|
16
|
+
redirect_to session[:redirect] || root_url
|
17
|
+
else
|
18
|
+
render '/auth/failure'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure
|
23
|
+
render :inline => 'Snowman says no. <div id="snowman" style="text-align:center; font-size:4000%;">☃</div>'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/config/routes.rb
ADDED
data/google_auth.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "google_auth/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "google_auth"
|
7
|
+
s.version = GoogleAuth::VERSION
|
8
|
+
s.authors = ["Burke Libbey"]
|
9
|
+
s.email = ["burke.libbey@shopify.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Convenience wrapper of omniauth-google-apps}
|
12
|
+
s.description = %q{Convenience wrapper for omniauth-google-apps: Makes a lot of assumptions, requires less configuration.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'omniauth-google-apps'
|
20
|
+
end
|
data/lib/google_auth.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'google_auth/version'
|
2
|
+
require 'google_auth/engine'
|
3
|
+
require 'google_auth/controller'
|
4
|
+
|
5
|
+
module GoogleAuth
|
6
|
+
|
7
|
+
def self.domain
|
8
|
+
Rails.application.config.google_auth.domain or
|
9
|
+
raise "domain missing! Add config.google_auth.domain to an initializer."
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.path
|
13
|
+
Rails.application.config.google_auth.path or
|
14
|
+
'g'
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.user_class
|
18
|
+
klass = Rails.application.config.google_auth.path
|
19
|
+
return klass if klass
|
20
|
+
|
21
|
+
begin
|
22
|
+
User
|
23
|
+
rescue
|
24
|
+
raise "User class not found! Add config.google_auth.user_class to an initializer."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GoogleAuth
|
2
|
+
module Controller
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:before_filter, :ensure_authenticated)
|
6
|
+
base.send(:helper_method, :current_user)
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_user
|
10
|
+
@current_user ||= begin
|
11
|
+
GoogleAuth.user_class.find_by_id(session[:user_id]) if session[:user_id]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def ensure_authenticated
|
16
|
+
unless current_user
|
17
|
+
session[:redirect] = request.fullpath
|
18
|
+
redirect_to(login_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'omniauth-google-apps'
|
2
|
+
require 'openid/store/filesystem'
|
3
|
+
|
4
|
+
module GoogleAuth
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
|
7
|
+
config.google_auth = ActiveSupport::OrderedOptions.new
|
8
|
+
|
9
|
+
initializer 'google_auth' do |app|
|
10
|
+
# OpenID.fetcher.ca_file = 'vendor/ca-bundle.crt'
|
11
|
+
app.middleware.use OmniAuth::Builder do
|
12
|
+
provider :google_apps,
|
13
|
+
store: OpenID::Store::Filesystem.new('./tmp'),
|
14
|
+
name: GoogleAuth.path,
|
15
|
+
domain: GoogleAuth.domain
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Burke Libbey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-google-apps
|
16
|
+
requirement: &70187256837100 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70187256837100
|
25
|
+
description: ! 'Convenience wrapper for omniauth-google-apps: Makes a lot of assumptions,
|
26
|
+
requires less configuration.'
|
27
|
+
email:
|
28
|
+
- burke.libbey@shopify.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/controllers/sessions_controller.rb
|
38
|
+
- config/routes.rb
|
39
|
+
- google_auth.gemspec
|
40
|
+
- lib/google_auth.rb
|
41
|
+
- lib/google_auth/controller.rb
|
42
|
+
- lib/google_auth/engine.rb
|
43
|
+
- lib/google_auth/version.rb
|
44
|
+
homepage: ''
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.11
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Convenience wrapper of omniauth-google-apps
|
68
|
+
test_files: []
|