sinatra-g_auth 0.0.1
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/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +20 -0
- data/lib/sinatra/g_auth/version.rb +5 -0
- data/lib/sinatra/g_auth.rb +36 -0
- data/sinatra-g_auth.gemspec +29 -0
- data/spec/sinatra/g_auth_spec.rb +43 -0
- data/spec/spec_helper.rb +11 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6689a1cca3315d1e6aec7332566beaabcd51f204
|
4
|
+
data.tar.gz: e8326137129f4a046e3cc1f5f3cda6952b435c0f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e791775addc452446b8af3ec727c27fe78eba313ec8b2c40795745050cc93960b1538e7894dcdd20f8e4b564acf4b74c8b0b33ab5b3c76657fea1cfcbc50d252
|
7
|
+
data.tar.gz: e33726d9dc7a18a42fccde827e75068b32add7657db54ee07b22f735dde196bc0a00acc15c8ea65a7bca42f6f62b2381957088e606d987c19d8f4a6cc43838a9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Eric Marden
|
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,29 @@
|
|
1
|
+
# SinatraGAuth
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sinatra_g_auth'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sinatra_g_auth
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
# environment
|
8
|
+
ENV['RACK_ENV'] ||= 'development'
|
9
|
+
|
10
|
+
# load path
|
11
|
+
lib_path = File.expand_path('../lib', __FILE__)
|
12
|
+
($:.unshift lib_path) unless ($:.include? lib_path)
|
13
|
+
|
14
|
+
Rake::TestTask.new do |t|
|
15
|
+
t.libs << "spec"
|
16
|
+
t.pattern = "spec/sinatra/**/*_spec.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
# tasks
|
20
|
+
task :default => [:test]
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra/g_auth/version'
|
3
|
+
require 'openid/store/filesystem'
|
4
|
+
require 'omniauth/strategies/google_apps'
|
5
|
+
|
6
|
+
module Sinatra
|
7
|
+
module GAuth
|
8
|
+
module Helpers
|
9
|
+
def protect_with_gauth!
|
10
|
+
redirect '/auth/g' unless session[:_gauth]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.registered(app)
|
15
|
+
app.helpers GAuth::Helpers
|
16
|
+
app.enable :sessions
|
17
|
+
app.set :gauth_domain, 'gmail.com'
|
18
|
+
app.set :gauth_redirect, '/'
|
19
|
+
app.set :gauth_tmp_dir, '/tmp'
|
20
|
+
|
21
|
+
app.use OmniAuth::Builder do
|
22
|
+
provider :google_apps, store: OpenID::Store::Filesystem.new(app.settings.gauth_tmp_dir), name: 'g', domain: app.settings.gauth_domain
|
23
|
+
end
|
24
|
+
|
25
|
+
app.post '/auth/g/callback' do
|
26
|
+
if auth = request.env['omniauth.auth']
|
27
|
+
session[:_gauth] = auth
|
28
|
+
redirect app.settings.gauth_redirect
|
29
|
+
else
|
30
|
+
halt 401, 'Authorization Failed.'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
register GAuth
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sinatra/g_auth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "sinatra-g_auth"
|
8
|
+
gem.version = Sinatra::GAuth::VERSION
|
9
|
+
gem.authors = ["Eric Marden"]
|
10
|
+
gem.email = ["eric@xentek.net"]
|
11
|
+
gem.description = %q{Sinatra + oAuth via Google Apps}
|
12
|
+
gem.summary = %q{Quickly add Google Apps authentication to any Sintra app.}
|
13
|
+
gem.homepage = "https://github.com/styleseek/sinatra-g_auth"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.add_dependency 'sinatra', '~> 1.4.0'
|
22
|
+
gem.add_dependency 'omniauth-google-apps', '~> 0.0.2'
|
23
|
+
|
24
|
+
gem.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
gem.add_development_dependency 'minitest'
|
27
|
+
gem.add_development_dependency 'minitest-reporters'
|
28
|
+
gem.add_development_dependency 'rack-test'
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
class GAuthApp < Sinatra::Base
|
6
|
+
register Sinatra::GAuth
|
7
|
+
set :gauth_redirect, '/not-protected'
|
8
|
+
|
9
|
+
get '/not-protected' do
|
10
|
+
"Hello! I'm not protected."
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/protected' do
|
14
|
+
protect_with_gauth!
|
15
|
+
"Hello! I'm protected with gauth."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Sinatra::GAuth do
|
20
|
+
include Rack::Test::Methods
|
21
|
+
def app
|
22
|
+
GAuthApp.new
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "if route is not protected" do
|
26
|
+
it 'will not redirect user' do
|
27
|
+
get '/not-protected'
|
28
|
+
last_response.status.must_equal 200
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "if route is protected" do
|
33
|
+
it 'will redirect user for authentication' do
|
34
|
+
get '/protected'
|
35
|
+
last_response.status.must_equal 302
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'will redirect to /auth/g' do
|
39
|
+
get '/protected'
|
40
|
+
last_response.original_headers['Location'].must_equal 'http://example.org/auth/g'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
ENV['RACK_ENV'] = 'test'
|
4
|
+
lib_path = File.expand_path('../lib', __FILE__)
|
5
|
+
($:.unshift lib_path) unless ($:.include? lib_path)
|
6
|
+
Bundler.setup(:default, ENV['RACK_ENV'])
|
7
|
+
require 'rack/test'
|
8
|
+
require 'sinatra/g_auth'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
require 'minitest/reporters'
|
11
|
+
MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-g_auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Marden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sinatra
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-google-apps
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rack-test
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Sinatra + oAuth via Google Apps
|
112
|
+
email:
|
113
|
+
- eric@xentek.net
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/sinatra/g_auth.rb
|
125
|
+
- lib/sinatra/g_auth/version.rb
|
126
|
+
- sinatra-g_auth.gemspec
|
127
|
+
- spec/sinatra/g_auth_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: https://github.com/styleseek/sinatra-g_auth
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.0.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Quickly add Google Apps authentication to any Sintra app.
|
153
|
+
test_files:
|
154
|
+
- spec/sinatra/g_auth_spec.rb
|
155
|
+
- spec/spec_helper.rb
|