dispatch-auth 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +23 -0
- data/lib/dispatch.rb +1 -0
- data/lib/dispatch/auth.rb +34 -0
- data/lib/dispatch/auth/errors.rb +21 -0
- data/lib/dispatch/auth/version.rb +5 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ec69785f12223e77e1d2a8c7911b440294b70f0
|
4
|
+
data.tar.gz: dc958f0cc9fc47af41c1e88acd6acf752b66a29e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ccf167b6fda2df77bb92367b05f48bceeb4d949497c3323c4e4c3696b0676e298e03cb65e780701399b0cb65d019993f020c24b683cf17926f3caa03970144b
|
7
|
+
data.tar.gz: 6a1301a0beae0cc7ddaef7b63330b03695056691a9c6dc37911110bdfa9f440784b28fd613590ba1b9081630cfcca817bb57a9eed4b857167ac31599fa6fb1d8
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Dispatch::Auth
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dispatch-auth'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dispatch-auth
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
data/lib/dispatch.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'dispatch/auth'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require_relative 'auth/errors'
|
3
|
+
|
4
|
+
module Dispatch
|
5
|
+
module Auth
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def authenticate_request!(env)
|
10
|
+
headers.merge!('Content-Type' => 'application/json')
|
11
|
+
headers.merge!('Authorization' => get_auth_header(env)) || raise(Dispatch::Auth::TokenMissingError)
|
12
|
+
|
13
|
+
response = get(ENV['AUTH_ENDPOINT_URL'])
|
14
|
+
|
15
|
+
case response.code
|
16
|
+
when 401
|
17
|
+
raise Dispatch::Auth::NotAuthenticatedError
|
18
|
+
when 403
|
19
|
+
raise Dispatch::Auth::NotAuthorizedError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_auth_header(env)
|
24
|
+
r = Rack::Request.new(env)
|
25
|
+
header = r.env['HTTP_AUTHORIZATION']
|
26
|
+
token = r.params['access_token'] || r.params['bearer_token']
|
27
|
+
header ||= "Bearer #{token}" if token
|
28
|
+
raise(Dispatch::Auth::TokenMissingError) unless header
|
29
|
+
header
|
30
|
+
end
|
31
|
+
private :get_auth_header
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dispatch
|
2
|
+
module Auth
|
3
|
+
class TokenMissingError < StandardError
|
4
|
+
def message
|
5
|
+
'Authorization header required.'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class NotAuthenticatedError < StandardError
|
10
|
+
def message
|
11
|
+
'Request is not authenticated.'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class NotAuthorizedError < StandardError
|
16
|
+
def message
|
17
|
+
'You are not authorized to access this page.'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dispatch-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rilian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Gem to authenticate requests for Dispatch APIs, by passing Authorization
|
56
|
+
token to Dispatch Users API
|
57
|
+
email:
|
58
|
+
- dmitriyis@gmail.com
|
59
|
+
- creeonix@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- README.md
|
65
|
+
- lib/dispatch.rb
|
66
|
+
- lib/dispatch/auth.rb
|
67
|
+
- lib/dispatch/auth/errors.rb
|
68
|
+
- lib/dispatch/auth/version.rb
|
69
|
+
homepage: http://dispatch.me
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.2.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Gem to authenticate requests for Dispatch APIs
|
93
|
+
test_files: []
|