bouncer-client 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.document +5 -0
- data/.env +1 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/bouncer-client.gemspec +34 -0
- data/lib/bouncer-client.rb +2 -0
- data/lib/bouncer-client/.token.rb.swp +0 -0
- data/lib/bouncer-client/client.rb +5 -0
- data/lib/bouncer-client/controller_mixin.rb +33 -0
- data/lib/bouncer-client/errors.rb +4 -0
- data/lib/bouncer-client/test_helpers.rb +33 -0
- data/lib/bouncer-client/token.rb +89 -0
- data/lib/bouncer-client/version.rb +3 -0
- data/spec/cassettes/bouncer/valid_admin.yml +93 -0
- data/spec/cassettes/bouncer/valid_device.yml +93 -0
- data/spec/model/.token_spec.rb.swp +0 -0
- data/spec/model/token_spec.rb +46 -0
- data/spec/spec_helper.rb +31 -0
- metadata +256 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2ad0e2ec88bc8cb14e047a2ca3b897d3a8f1435
|
4
|
+
data.tar.gz: e2dbd9c6b28f2d8c36c8f115c1366b6f622b0dd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebdee618ace3ec49907cf768aa4a36efc2acf76497790cbedd7602704556292ee95cf3555e4ae298bf3a830a42f1892e1eb448b9df582173dfee5c14aa684909
|
7
|
+
data.tar.gz: e96985c4cf00984253754d169911b57d7c26cfdc52b080a5a1fb0621b4e3443e03fd230732b1e6d1da8eee0ccf7219d665a8781b0975ce6c6e6a9675e16ad141
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Kurt Nelson
|
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,37 @@
|
|
1
|
+
# Bouncer::Client
|
2
|
+
[![Build Status](https://secure.travis-ci.org/MonsieurCode/bouncer-ruby.png)](http://travis-ci.org/MonsieurCode/bouncer-ruby)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/bouncer-client.png)](http://badge.fury.io/rb/bouncer-client)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/MonsieurCode/bouncer-ruby.png)](https://codeclimate.com/github/MonsieurCode/bouncer-ruby)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/MonsieurCode/bouncer-ruby/badge.svg)](https://coveralls.io/r/MonsieurCode/bouncer-ruby)
|
6
|
+
[![Dependency Status](https://gemnasium.com/MonsieurCode/bouncer-ruby.png)](https://gemnasium.com/MonsieurCode/bouncer-ruby)
|
7
|
+
[Documentation](http://rubydoc.info/gems/bouncer-client/)
|
8
|
+
|
9
|
+
TODO: Write a gem description
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'bouncer-client'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install bouncer-client
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
TODO: Write usage instructions here
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it ( https://github.com/MonsieurCode/bouncer-ruby/fork )
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bouncer-client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bouncer-client"
|
8
|
+
spec.version = Bouncer::VERSION
|
9
|
+
spec.authors = ["Kurt Nelson"]
|
10
|
+
spec.email = ["kurt@monsieur.co"]
|
11
|
+
spec.summary = %q{Allows Rails to easily use a Bouncer instance for authentication}
|
12
|
+
spec.description = %q{Enables using the Bouncer microservice for authentication. Includes test helpers, authentication helpers, and Redis caching}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday'
|
22
|
+
spec.add_dependency 'redis'
|
23
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'rdoc'
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'dotenv'
|
29
|
+
spec.add_development_dependency 'coveralls'
|
30
|
+
spec.add_development_dependency 'fakeredis'
|
31
|
+
spec.add_development_dependency 'pry'
|
32
|
+
spec.add_development_dependency 'vcr'
|
33
|
+
spec.add_development_dependency 'webmock'
|
34
|
+
end
|
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_support/rescuable'
|
2
|
+
module Bouncer
|
3
|
+
module ControllerMixin
|
4
|
+
def current_user
|
5
|
+
@token ||= Bouncer::Token.new(request.headers['authorization'])
|
6
|
+
end
|
7
|
+
|
8
|
+
def authenticate_user!
|
9
|
+
raise UnauthenticatedError unless Bouncer::Token.present? request
|
10
|
+
raise UnauthenticatedError unless current_user.validate!
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticate_super_admin!
|
14
|
+
authenticate_user!
|
15
|
+
raise UnauthorizedError unless current_user.super_admin?
|
16
|
+
end
|
17
|
+
|
18
|
+
def authenticate_machine!
|
19
|
+
authenticate_user!
|
20
|
+
raise UnauthorizedError unless current_user.device?
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def unauthorized(error)
|
26
|
+
head :forbidden
|
27
|
+
end
|
28
|
+
|
29
|
+
def unauthenticated(error)
|
30
|
+
head :unauthorized
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Bouncer
|
2
|
+
module TestHelpers
|
3
|
+
def super_admin_token id = SecureRandom.uuid
|
4
|
+
token = user_token id
|
5
|
+
allow(token).to receive(:super_admin?).and_return(true)
|
6
|
+
token
|
7
|
+
end
|
8
|
+
|
9
|
+
def user_token id = SecureRandom.uuid
|
10
|
+
token = valid_token id
|
11
|
+
allow(token).to receive(:user?).and_return(true)
|
12
|
+
token
|
13
|
+
end
|
14
|
+
|
15
|
+
def machine_token id = SecureRandom.uuid
|
16
|
+
token = valid_token id
|
17
|
+
allow(token).to receive(:device?).and_return(true)
|
18
|
+
token
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_token mock_id = "abunchofcrap"
|
22
|
+
token = double("Bouncer::Token")
|
23
|
+
allow(token).to receive(:validate!).and_return(true)
|
24
|
+
allow(token).to receive(:id).and_return(mock_id.to_s)
|
25
|
+
allow(token).to receive(:device?)
|
26
|
+
allow(token).to receive(:user?)
|
27
|
+
allow(token).to receive(:super_admin?)
|
28
|
+
allow(Bouncer::Token).to receive(:present?).and_return(true)
|
29
|
+
allow(Bouncer::Token).to receive(:new).and_return(token)
|
30
|
+
token
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'redis'
|
3
|
+
module Bouncer
|
4
|
+
class Token
|
5
|
+
attr_reader :payload
|
6
|
+
def initialize token
|
7
|
+
@token = token.split(' ')[1]
|
8
|
+
return get_from_bouncer unless redis.exists "TOKEN:#{@token}"
|
9
|
+
|
10
|
+
data = redis.get("TOKEN:#{@token}")
|
11
|
+
begin
|
12
|
+
@payload = JSON.parse data
|
13
|
+
rescue JSON::ParserError
|
14
|
+
get_from_bouncer
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def id
|
19
|
+
if device?
|
20
|
+
@payload["devices"]["id"]
|
21
|
+
else
|
22
|
+
@payload["users"]["id"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def email
|
27
|
+
@payload["users"]["email"] if user?
|
28
|
+
end
|
29
|
+
|
30
|
+
def phone
|
31
|
+
@payload["users"]["phone"] if user?
|
32
|
+
end
|
33
|
+
|
34
|
+
def image
|
35
|
+
@payload["users"]["image"] if user?
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate!
|
39
|
+
return false unless @payload
|
40
|
+
@payload["users"] != nil || @payload["devices"] != nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def super_admin?
|
44
|
+
@payload["users"]["super_admin"] == true
|
45
|
+
end
|
46
|
+
|
47
|
+
def device?
|
48
|
+
@payload['devices'] && !@payload['devices'].empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def user?
|
52
|
+
@payload['users'] && !@payload['users'].empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.present? request
|
56
|
+
return false unless auth_header = request.headers['authorization']
|
57
|
+
auth_header.split(' ')[0] == 'Bearer'
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def get_from_bouncer
|
63
|
+
raise "No BOUNCER_URL" unless ENV['BOUNCER_URL']
|
64
|
+
conn = Faraday.new(url: ENV['BOUNCER_URL']) do |faraday|
|
65
|
+
faraday.request :url_encoded
|
66
|
+
faraday.adapter Faraday.default_adapter
|
67
|
+
faraday.headers['Content-Type'] = 'application/json'
|
68
|
+
faraday.headers['Authorization'] = 'Bearer ' + @token
|
69
|
+
end
|
70
|
+
|
71
|
+
response = conn.get("/oauth/token/info")
|
72
|
+
@expires_in = JSON.parse(response.body)["expires_in_seconds"]
|
73
|
+
if response.success?
|
74
|
+
raw = conn.get("/me")
|
75
|
+
if raw.success?
|
76
|
+
@payload = JSON.parse(raw.body)
|
77
|
+
redis.setex("TOKEN:#{@token}", @expires_in, @payload.to_json)
|
78
|
+
return
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@payload = nil
|
82
|
+
redis.del("TOKEN:#{@token}")
|
83
|
+
end
|
84
|
+
|
85
|
+
def redis
|
86
|
+
Redis.current
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://mbouncer.herokuapp.com/oauth/token/info
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- Bearer 5d9680a671c060d08836940e50ded28d361944767a9436fe6df5e7462087a8ee
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
Server:
|
18
|
+
- Cowboy
|
19
|
+
Connection:
|
20
|
+
- close
|
21
|
+
Date:
|
22
|
+
- Tue, 03 Feb 2015 16:09:42 GMT
|
23
|
+
Status:
|
24
|
+
- 200 OK
|
25
|
+
X-Frame-Options:
|
26
|
+
- SAMEORIGIN
|
27
|
+
X-Xss-Protection:
|
28
|
+
- 1; mode=block
|
29
|
+
X-Content-Type-Options:
|
30
|
+
- nosniff
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Etag:
|
34
|
+
- W/"6f76c9ea61a57b7e2683af4672bdf138"
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
X-Request-Id:
|
38
|
+
- d6709999-7ff6-4b9c-bdf7-6cceb4672c23
|
39
|
+
X-Runtime:
|
40
|
+
- '0.011506'
|
41
|
+
Via:
|
42
|
+
- 1.1 vegur
|
43
|
+
body:
|
44
|
+
encoding: UTF-8
|
45
|
+
string: '{"resource_owner_id":"54bff1bcd43b8d0009000001","scopes":["user"],"expires_in_seconds":5436,"application":{"uid":null},"created_at":1422978018}'
|
46
|
+
http_version:
|
47
|
+
recorded_at: Tue, 03 Feb 2015 16:09:41 GMT
|
48
|
+
- request:
|
49
|
+
method: get
|
50
|
+
uri: https://mbouncer.herokuapp.com/me
|
51
|
+
body:
|
52
|
+
encoding: US-ASCII
|
53
|
+
string: ''
|
54
|
+
headers:
|
55
|
+
Authorization:
|
56
|
+
- Bearer 5d9680a671c060d08836940e50ded28d361944767a9436fe6df5e7462087a8ee
|
57
|
+
response:
|
58
|
+
status:
|
59
|
+
code: 200
|
60
|
+
message: OK
|
61
|
+
headers:
|
62
|
+
Server:
|
63
|
+
- Cowboy
|
64
|
+
Connection:
|
65
|
+
- close
|
66
|
+
Date:
|
67
|
+
- Tue, 03 Feb 2015 16:09:45 GMT
|
68
|
+
Status:
|
69
|
+
- 200 OK
|
70
|
+
X-Frame-Options:
|
71
|
+
- SAMEORIGIN
|
72
|
+
X-Xss-Protection:
|
73
|
+
- 1; mode=block
|
74
|
+
X-Content-Type-Options:
|
75
|
+
- nosniff
|
76
|
+
Content-Type:
|
77
|
+
- application/json; charset=utf-8
|
78
|
+
Etag:
|
79
|
+
- W/"7c3d209db250608abd463fb92610674c"
|
80
|
+
Cache-Control:
|
81
|
+
- max-age=0, private, must-revalidate
|
82
|
+
X-Request-Id:
|
83
|
+
- 5023277a-bf93-4ba0-a7ff-b5d6ae4e3fe2
|
84
|
+
X-Runtime:
|
85
|
+
- '0.406796'
|
86
|
+
Via:
|
87
|
+
- 1.1 vegur
|
88
|
+
body:
|
89
|
+
encoding: UTF-8
|
90
|
+
string: '{"users":{"id":"54bff1bcd43b8d0009000001","email":"kurtisnelson@gmail.com","image":"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p50x50/1422503_10201617485134756_581959844_n.jpg?oh=3c43c2d34d7d47e80db7fa70bb785d25\u0026oe=5520E205\u0026__gda__=1431516611_892762dead4a80879480e80af6e218cb","super_admin": true, "phone":"4075120689","confirmed_at":"2015-01-21T18:36:44.270Z"},"links":{"self":{"href":"https://bouncer.monsieur.co/users/54bff1bcd43b8d0009000001"}}}'
|
91
|
+
http_version:
|
92
|
+
recorded_at: Tue, 03 Feb 2015 16:09:44 GMT
|
93
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,93 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://mbouncer.herokuapp.com/oauth/token/info
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- Bearer 0f99d628d2ae1d20ebe02dc794348dcd351e322a920df3bf0de6929987c8c59f
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
Server:
|
18
|
+
- Cowboy
|
19
|
+
Connection:
|
20
|
+
- close
|
21
|
+
Date:
|
22
|
+
- Wed, 28 Jan 2015 15:59:40 GMT
|
23
|
+
Status:
|
24
|
+
- 200 OK
|
25
|
+
X-Frame-Options:
|
26
|
+
- SAMEORIGIN
|
27
|
+
X-Xss-Protection:
|
28
|
+
- 1; mode=block
|
29
|
+
X-Content-Type-Options:
|
30
|
+
- nosniff
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Etag:
|
34
|
+
- W/"f5d4810748f6c26c7b4df2173a949a31"
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
X-Request-Id:
|
38
|
+
- 53bbf8a3-4f0e-4782-8854-3d99a23cd69d
|
39
|
+
X-Runtime:
|
40
|
+
- '0.004567'
|
41
|
+
Via:
|
42
|
+
- 1.1 vegur
|
43
|
+
body:
|
44
|
+
encoding: UTF-8
|
45
|
+
string: '{"resource_owner_id":"54c904b2773db80010000001","scopes":["machine"],"expires_in_seconds":85702,"application":{"uid":null},"created_at":1422460082}'
|
46
|
+
http_version:
|
47
|
+
recorded_at: Wed, 28 Jan 2015 15:59:42 GMT
|
48
|
+
- request:
|
49
|
+
method: get
|
50
|
+
uri: https://mbouncer.herokuapp.com/me
|
51
|
+
body:
|
52
|
+
encoding: US-ASCII
|
53
|
+
string: ''
|
54
|
+
headers:
|
55
|
+
Authorization:
|
56
|
+
- Bearer 0f99d628d2ae1d20ebe02dc794348dcd351e322a920df3bf0de6929987c8c59f
|
57
|
+
response:
|
58
|
+
status:
|
59
|
+
code: 200
|
60
|
+
message: OK
|
61
|
+
headers:
|
62
|
+
Server:
|
63
|
+
- Cowboy
|
64
|
+
Connection:
|
65
|
+
- close
|
66
|
+
Date:
|
67
|
+
- Wed, 28 Jan 2015 15:59:44 GMT
|
68
|
+
Status:
|
69
|
+
- 200 OK
|
70
|
+
X-Frame-Options:
|
71
|
+
- SAMEORIGIN
|
72
|
+
X-Xss-Protection:
|
73
|
+
- 1; mode=block
|
74
|
+
X-Content-Type-Options:
|
75
|
+
- nosniff
|
76
|
+
Content-Type:
|
77
|
+
- application/json; charset=utf-8
|
78
|
+
Etag:
|
79
|
+
- W/"54fec5a35fa28357fdad8184627a1bbf"
|
80
|
+
Cache-Control:
|
81
|
+
- max-age=0, private, must-revalidate
|
82
|
+
X-Request-Id:
|
83
|
+
- b55a5f05-bd6c-41fa-aad7-d4468a5b3836
|
84
|
+
X-Runtime:
|
85
|
+
- '0.031087'
|
86
|
+
Via:
|
87
|
+
- 1.1 vegur
|
88
|
+
body:
|
89
|
+
encoding: UTF-8
|
90
|
+
string: '{"devices":{"id":"54d104bfe920dcdb20000001","serial":"123456","user":"54c6acc0e920dc9956000007","token":"54d104bfe920dcdb20000002","created_at":"2015-02-03T17:26:23.218Z"},"links":{"self":{"href":"http://localhost:8000/devices/54d104bfe920dcdb20000001"}},"linked":{"tokens":[{"id":"54d104bfe920dcdb20000002","resource_owner_id":"54d104bfe920dcdb20000001","refresh_token":"a3db24a6b7e4acf9089f392bcee588d485ba43735bc80fadfc75b743707f5443","expires_in_seconds":86351,"access_token":"b23741cdc650666c1e3eaff8eb95cee0e120d65d61de25ff8e5d6ee64757b715"}],"users":[{"email":"kurt@monsieur.co","id":"54c6acc0e920dc9956000007","image":"https://secure.gravatar.com/avatar/ebfcbe366c47be18e8d3d6eb13d51d17?d=mm","super_admin":true}]}}'
|
91
|
+
http_version:
|
92
|
+
recorded_at: Wed, 28 Jan 2015 15:59:45 GMT
|
93
|
+
recorded_with: VCR 2.9.3
|
Binary file
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bouncer::Token do
|
4
|
+
let(:admin_token) { Bouncer::Token.new 'Bearer 5d9680a671c060d08836940e50ded28d361944767a9436fe6df5e7462087a8ee' }
|
5
|
+
let(:device_token) { Bouncer::Token.new 'Bearer b23741cdc650666c1e3eaff8eb95cee0e120d65d61de25ff8e5d6ee64757b715'}
|
6
|
+
describe "#validate!" do
|
7
|
+
it "validates admin tokens" do
|
8
|
+
VCR.use_cassette 'bouncer/valid_admin' do
|
9
|
+
expect(admin_token.validate!).to eq true #hit network
|
10
|
+
expect(admin_token.validate!).to eq true #redis cache
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'validates device tokens' do
|
15
|
+
VCR.use_cassette 'bouncer/valid_device' do
|
16
|
+
expect(device_token.validate!).to eq true
|
17
|
+
expect(device_token.validate!).to eq true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#super_admin?" do
|
23
|
+
it "returns true" do
|
24
|
+
VCR.use_cassette 'bouncer/valid_admin' do
|
25
|
+
expect(admin_token).to be_super_admin
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#device?" do
|
31
|
+
context "device token" do
|
32
|
+
it "returns true" do
|
33
|
+
VCR.use_cassette 'bouncer/valid_device' do
|
34
|
+
expect(device_token).to be_device
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "user" do
|
39
|
+
it 'returns false' do
|
40
|
+
VCR.use_cassette 'bouncer/valid_admin' do
|
41
|
+
expect(admin_token).to_not be_device
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'fakeredis/rspec'
|
4
|
+
require "codeclimate-test-reporter"
|
5
|
+
CodeClimate::TestReporter.start
|
6
|
+
require 'coveralls'
|
7
|
+
Coveralls.wear! 'rails'
|
8
|
+
require 'pry'
|
9
|
+
require 'rspec'
|
10
|
+
require 'vcr'
|
11
|
+
|
12
|
+
require 'dotenv'
|
13
|
+
Dotenv.load
|
14
|
+
|
15
|
+
require 'bouncer-client'
|
16
|
+
|
17
|
+
#Setup test constants
|
18
|
+
|
19
|
+
# Requires supporting files with custom matchers and macros, etc,
|
20
|
+
# in ./support/ and its subdirectories.
|
21
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
VCR.configure do |c|
|
25
|
+
c.cassette_library_dir = 'spec/cassettes'
|
26
|
+
c.hook_into :webmock
|
27
|
+
c.filter_sensitive_data('<ADMIN_TOKEN>') { ENV['ADMIN_TOKEN'] }
|
28
|
+
c.filter_sensitive_data('<DEVICE_TOKEN>') { ENV['DEVICE_TOKEN'] }
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bouncer-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kurt Nelson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
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: rdoc
|
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: bundler
|
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
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dotenv
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: fakeredis
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: vcr
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: webmock
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: Enables using the Bouncer microservice for authentication. Includes test
|
196
|
+
helpers, authentication helpers, and Redis caching
|
197
|
+
email:
|
198
|
+
- kurt@monsieur.co
|
199
|
+
executables: []
|
200
|
+
extensions: []
|
201
|
+
extra_rdoc_files: []
|
202
|
+
files:
|
203
|
+
- ".coveralls.yml"
|
204
|
+
- ".document"
|
205
|
+
- ".env"
|
206
|
+
- ".gitignore"
|
207
|
+
- ".rspec"
|
208
|
+
- ".travis.yml"
|
209
|
+
- Gemfile
|
210
|
+
- LICENSE.txt
|
211
|
+
- README.md
|
212
|
+
- Rakefile
|
213
|
+
- bouncer-client.gemspec
|
214
|
+
- lib/bouncer-client.rb
|
215
|
+
- lib/bouncer-client/.token.rb.swp
|
216
|
+
- lib/bouncer-client/client.rb
|
217
|
+
- lib/bouncer-client/controller_mixin.rb
|
218
|
+
- lib/bouncer-client/errors.rb
|
219
|
+
- lib/bouncer-client/test_helpers.rb
|
220
|
+
- lib/bouncer-client/token.rb
|
221
|
+
- lib/bouncer-client/version.rb
|
222
|
+
- spec/cassettes/bouncer/valid_admin.yml
|
223
|
+
- spec/cassettes/bouncer/valid_device.yml
|
224
|
+
- spec/model/.token_spec.rb.swp
|
225
|
+
- spec/model/token_spec.rb
|
226
|
+
- spec/spec_helper.rb
|
227
|
+
homepage: ''
|
228
|
+
licenses:
|
229
|
+
- MIT
|
230
|
+
metadata: {}
|
231
|
+
post_install_message:
|
232
|
+
rdoc_options: []
|
233
|
+
require_paths:
|
234
|
+
- lib
|
235
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
236
|
+
requirements:
|
237
|
+
- - ">="
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
240
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
|
+
requirements:
|
242
|
+
- - ">="
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: '0'
|
245
|
+
requirements: []
|
246
|
+
rubyforge_project:
|
247
|
+
rubygems_version: 2.2.2
|
248
|
+
signing_key:
|
249
|
+
specification_version: 4
|
250
|
+
summary: Allows Rails to easily use a Bouncer instance for authentication
|
251
|
+
test_files:
|
252
|
+
- spec/cassettes/bouncer/valid_admin.yml
|
253
|
+
- spec/cassettes/bouncer/valid_device.yml
|
254
|
+
- spec/model/.token_spec.rb.swp
|
255
|
+
- spec/model/token_spec.rb
|
256
|
+
- spec/spec_helper.rb
|