rack-federated-auth 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -2,48 +2,81 @@ require 'sinatra'
2
2
 
3
3
  module RackFederatedAuth
4
4
  class Authentication < Sinatra::Base
5
- attr_accessor :auth_url
5
+ attr_accessor :auth_scope
6
6
  attr_accessor :email_filter
7
7
  attr_accessor :failure_message
8
8
 
9
+ attr_accessor :auth_prefix
10
+ attr_accessor :auth_url
11
+ attr_accessor :success_url
12
+ attr_accessor :failure_url
13
+
14
+ # Set up federated authentication
15
+ #
16
+ # auth_scope is the session key which will be used to check if the user has authenticated. Allows basic role-based authentication
17
+ # email_filter is a regex which a user's email must match to be authorized
18
+ # failure_message is the text which will be shown to users after failed auth - use it to help them authenticate correctly
19
+ # auth_prefix will be prepended to the OmniAuth urls (callbacks, etc).
20
+ # auth_url determines which auth strategy will be used - see OmniAuth's docs for more details
21
+ # success_url is the url the user will be redirected to after successful authentication
22
+ # failure_url for failed authentication (or emails that don't match email_filter)
23
+ #
9
24
  def initialize(app)
10
- @auth_url = "/auth/google_oauth2"
25
+ @auth_scope = "authorized"
11
26
  @email_filter = /.*/
12
27
  @failure_message = "Authentication failed. Click <a href='#{@auth_url}'>here</a> to try again"
28
+
29
+ @auth_prefix = "/auth"
30
+ @auth_url = nil
31
+ @success_url = '/'
32
+ @failure_url = nil
13
33
 
14
34
  yield self if block_given?
15
35
 
16
- super(app)
17
- end
36
+ @auth_url ||= "#{@auth_prefix}/google_oauth2"
37
+ @failure_url ||= "#{@auth_prefix}/failure"
18
38
 
19
- def authenticated?
20
- !session['authorized'].nil? and session['authorized']
39
+ super(app)
21
40
  end
22
41
 
42
+ # Make sure users are authenticated
43
+ #
44
+ # NOTE: This should really be aware of auth_prefix
23
45
  before /^(?!\/(auth))/ do
24
46
  redirect @auth_url unless authenticated?
25
47
  end
26
48
 
49
+ # Handle federated authentication callbacks
50
+ #
51
+ # This expects to be passed the authenticated user's email address. OmniAuth
52
+ # should normalize most of that stuff.
53
+ #
27
54
  get "/auth/:service/callback" do
28
55
  puts "New #{params[:service]} auth: #{request.env['omniauth.auth']}"
29
56
  begin
30
57
  if request.env['omniauth.auth']['info']['email'].match(@email_filter)
31
- puts "email matches filter"
32
- session['authorized'] = true
33
- redirect '/'
58
+ puts "email matches filter, redirecting to #{@success_url}"
59
+ session[@auth_scope] = true
60
+ redirect @success_url
34
61
  else
35
- puts "email doesn't match filter"
36
- redirect '/auth/failure'
62
+ puts "email doesn't match filter, redirecting to #{@failure_url}"
63
+ redirect @failure_url
37
64
  end
38
65
  rescue
39
66
  puts "Auth failure :("
40
67
  session['authorized'] = false
41
- redirect '/auth/failure'
68
+ redirect @failure_url
42
69
  end
43
70
  end
44
71
 
45
72
  get '/auth/failure' do
46
73
  "<html><body>#{@failure_message}</body></html>"
47
74
  end
75
+
76
+ private
77
+
78
+ def authenticated?
79
+ !session[@auth_scope].nil? and session[@auth_scope]
80
+ end
48
81
  end
49
82
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rack-federated-auth"
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Michael"]
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.homepage = "http://github.com/kerinin/rack-federated-auth"
33
33
  s.licenses = ["MIT"]
34
34
  s.require_paths = ["lib"]
35
- s.rubygems_version = "1.8.10"
35
+ s.rubygems_version = "1.8.15"
36
36
  s.summary = "Rack middleware using for federated authentication"
37
37
 
38
38
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,79 +1,107 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-federated-auth
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Ryan Michael
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-03-20 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: omniauth
16
- requirement: &2169195240 !ruby/object:Gem::Requirement
17
+
18
+ date: 2012-03-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
22
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ prerelease: false
31
+ requirement: *id001
32
+ name: omniauth
22
33
  type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
23
44
  prerelease: false
24
- version_requirements: *2169195240
25
- - !ruby/object:Gem::Dependency
45
+ requirement: *id002
26
46
  name: shoulda
27
- requirement: &2169194700 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
47
  type: :development
34
- prerelease: false
35
- version_requirements: *2169194700
36
- - !ruby/object:Gem::Dependency
37
- name: rdoc
38
- requirement: &2169194200 !ruby/object:Gem::Requirement
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
39
50
  none: false
40
- requirements:
51
+ requirements:
41
52
  - - ~>
42
- - !ruby/object:Gem::Version
43
- version: '3.12'
44
- type: :development
53
+ - !ruby/object:Gem::Version
54
+ hash: 31
55
+ segments:
56
+ - 3
57
+ - 12
58
+ version: "3.12"
45
59
  prerelease: false
46
- version_requirements: *2169194200
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: &2169193720 !ruby/object:Gem::Requirement
60
+ requirement: *id003
61
+ name: rdoc
62
+ type: :development
63
+ - !ruby/object:Gem::Dependency
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
50
65
  none: false
51
- requirements:
66
+ requirements:
52
67
  - - ~>
53
- - !ruby/object:Gem::Version
68
+ - !ruby/object:Gem::Version
69
+ hash: 23
70
+ segments:
71
+ - 1
72
+ - 0
73
+ - 0
54
74
  version: 1.0.0
55
- type: :development
56
75
  prerelease: false
57
- version_requirements: *2169193720
58
- - !ruby/object:Gem::Dependency
59
- name: jeweler
60
- requirement: &2169193240 !ruby/object:Gem::Requirement
76
+ requirement: *id004
77
+ name: bundler
78
+ type: :development
79
+ - !ruby/object:Gem::Dependency
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
61
81
  none: false
62
- requirements:
82
+ requirements:
63
83
  - - ~>
64
- - !ruby/object:Gem::Version
84
+ - !ruby/object:Gem::Version
85
+ hash: 49
86
+ segments:
87
+ - 1
88
+ - 8
89
+ - 3
65
90
  version: 1.8.3
66
- type: :development
67
91
  prerelease: false
68
- version_requirements: *2169193240
92
+ requirement: *id005
93
+ name: jeweler
94
+ type: :development
69
95
  description: Provides a simple authentication middleware to lock down Rack-based apps
70
96
  email: kerinin@gmail.com
71
97
  executables: []
98
+
72
99
  extensions: []
73
- extra_rdoc_files:
100
+
101
+ extra_rdoc_files:
74
102
  - LICENSE.txt
75
103
  - README.md
76
- files:
104
+ files:
77
105
  - .document
78
106
  - Gemfile
79
107
  - Gemfile.lock
@@ -86,31 +114,37 @@ files:
86
114
  - test/helper.rb
87
115
  - test/test_rack-federated-auth.rb
88
116
  homepage: http://github.com/kerinin/rack-federated-auth
89
- licenses:
117
+ licenses:
90
118
  - MIT
91
119
  post_install_message:
92
120
  rdoc_options: []
93
- require_paths:
121
+
122
+ require_paths:
94
123
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
124
+ required_ruby_version: !ruby/object:Gem::Requirement
96
125
  none: false
97
- requirements:
98
- - - ! '>='
99
- - !ruby/object:Gem::Version
100
- version: '0'
101
- segments:
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
102
131
  - 0
103
- hash: -323311014631924913
104
- required_rubygems_version: !ruby/object:Gem::Requirement
132
+ version: "0"
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
134
  none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
141
+ version: "0"
110
142
  requirements: []
143
+
111
144
  rubyforge_project:
112
- rubygems_version: 1.8.10
145
+ rubygems_version: 1.8.15
113
146
  signing_key:
114
147
  specification_version: 3
115
148
  summary: Rack middleware using for federated authentication
116
149
  test_files: []
150
+