rack-icis_identity_auth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ Rack Middleware for ICIS Identity Service Auth
2
+ ==============================================
3
+
4
+ Too cool for schoolâ„¢
@@ -0,0 +1,45 @@
1
+ require 'httparty'
2
+
3
+ module Rack
4
+ class IcisIdentityAuth
5
+ ROOT_URL = 'http://icis-identity-example.herokuapp.com/api/v1/verify.json'
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ token = env['HTTP_X_BEARER_TOKEN']
13
+ uid = env['HTTP_X_UID']
14
+ app_name = env['HTTP_X_APP_NAME']
15
+
16
+ return forbidden unless token && uid && app_name
17
+
18
+ response = HTTParty.get "#{ROOT_URL}?id=#{uid}&token=#{token}&app_name=#{app_name}"
19
+
20
+ case response.code
21
+ when 403
22
+ forbidden
23
+ when 404
24
+ error_code(404, 'Not Found')
25
+ when 500
26
+ error_code(500, 'Server Error')
27
+ when 503
28
+ error_code(503, 'Maintenance')
29
+ when 504
30
+ error_code(504, 'System Down')
31
+ end
32
+
33
+ @app.call(env)
34
+ end
35
+
36
+ private
37
+ def forbidden
38
+ error_code(403, 'Unauthorized')
39
+ end
40
+
41
+ def error_code(code, message)
42
+ [code, {'Content-Type' => 'text/plain'}, [message]]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rack-icis_identity_auth"
3
+ s.version = "0.1.0"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Patrick Robertson"]
7
+ s.date = "2013-04-11"
8
+ s.description = "Middleware that allows you to authenticate header-based auth request on ICIS services."
9
+ s.email = "patricksrobertson@gmail.com"
10
+ s.files = [
11
+ "README.md",
12
+ "lib/rack/icis_identity_auth.rb",
13
+ "rack-icis_identity_auth.gemspec",
14
+ ]
15
+ s.homepage = "http://github.com/patricksrobertson/rack-icis_identity_auth"
16
+ s.licenses = ["MIT"]
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = "1.8.24"
19
+ s.summary = "Middleware for ICIS service authentication."
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<rack>, [">= 0"])
26
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<rack>, [">= 0"])
29
+ s.add_dependency(%q<httparty>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<rack>, [">= 0"])
33
+ s.add_dependency(%q<httparty>, [">= 0"])
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-icis_identity_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patrick Robertson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: httparty
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Middleware that allows you to authenticate header-based auth request
47
+ on ICIS services.
48
+ email: patricksrobertson@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - README.md
54
+ - lib/rack/icis_identity_auth.rb
55
+ - rack-icis_identity_auth.gemspec
56
+ homepage: http://github.com/patricksrobertson/rack-icis_identity_auth
57
+ licenses:
58
+ - MIT
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.24
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Middleware for ICIS service authentication.
81
+ test_files: []