grape_devise_token_auth 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/README.md +24 -8
- data/lib/grape_devise_token_auth/auth_headers.rb +1 -1
- data/lib/grape_devise_token_auth/auth_helpers.rb +1 -1
- data/lib/grape_devise_token_auth/devise_interface.rb +1 -1
- data/lib/grape_devise_token_auth/token_authorizer.rb +9 -1
- data/lib/grape_devise_token_auth/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20ce9019cdda54279d483b4e1d83494fff408872
|
4
|
+
data.tar.gz: d9f9365c4915ca9384124ed3d06e519ba33128d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 574a15895c934d5e7c309bff9021035016d40e650b00bd2e9cf25e3c88b4d6f52c9458d2b399cef2dffa4770a3568c5182b09fac845b113785c70944455bade8
|
7
|
+
data.tar.gz: f344a3e4e844587ffc6607e5d3f14b6af9d192033104e6a9fae97d4c65527a850ce9e7199be51e93306d5399d41fb69d21107a621bfee8bd3b225e8e35293e6a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# GrapeDeviseTokenAuth
|
2
2
|
|
3
|
-
GrapeDeviseTokenAuth gem is a
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
GrapeDeviseTokenAuth gem is a compatibility layer between [devise_token_auth][1]
|
4
|
+
and [grape][2]. It is useful when mounting a grape API in a rails application
|
5
|
+
where [devise][3] (or `devise_token_auth` + `devise`) is already present. It is
|
6
|
+
reliant on `devise_token_auth` and `devise`, therefore it is not suitable for
|
7
|
+
grape where these are not present. If you are looking for a pure grape solution,
|
8
|
+
you should check out [grape\_token\_auth][gta].
|
8
9
|
|
9
|
-
The majority of the hard work and credit goes to [Lyann Dylan
|
10
|
-
|
11
|
-
|
10
|
+
The majority of the hard work and credit goes to [Lyann Dylan Hurley][4] and his
|
11
|
+
fantastic [devise_token_auth][1] gem. I merely have ported this to work well
|
12
|
+
with grape.
|
12
13
|
|
13
14
|
## Installation
|
14
15
|
|
@@ -74,6 +75,20 @@ There is also a `authenticate_user` version of this helper (notice that it lacks
|
|
74
75
|
|
75
76
|
[A full example setup can be found here][6]
|
76
77
|
|
78
|
+
**Note about ignoring existing warden users**
|
79
|
+
|
80
|
+
If you are having issues with users persisting across logins or you do not want
|
81
|
+
to integrate with devise, you can disable the integration with devise during
|
82
|
+
setup as so:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
|
86
|
+
GrapeDeviseTokenAuth.setup! do |config|
|
87
|
+
config.ignore_existing_warden_users = true
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
|
77
92
|
## Testing and Example
|
78
93
|
|
79
94
|
Currently I am using [this repo][5] to test this gem, eventually I plan on
|
@@ -101,3 +116,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
101
116
|
[4]: https://github.com/lynndylanhurley
|
102
117
|
[5]: https://github.com/mcordell/rails_grape_auth
|
103
118
|
[6]: https://github.com/mcordell/rails_grape_auth/blob/7ca6b2f3d989fc23824aaf40fc353fc3e8de40ec/app/api/grape_api/posts.rb
|
119
|
+
[gta]: https://github.com/mcordell/grape_token_auth
|
@@ -8,7 +8,7 @@ module GrapeDeviseTokenAuth
|
|
8
8
|
# extracted and simplified from Devise
|
9
9
|
def set_user_in_warden(scope, resource)
|
10
10
|
scope = Devise::Mapping.find_scope!(scope)
|
11
|
-
warden.
|
11
|
+
warden.set_user(resource, scope: scope, store: false)
|
12
12
|
end
|
13
13
|
|
14
14
|
def mapping_to_class(m)
|
@@ -11,8 +11,12 @@ module GrapeDeviseTokenAuth
|
|
11
11
|
@resource_class = devise_interface.mapping_to_class(mapping)
|
12
12
|
return nil unless resource_class
|
13
13
|
|
14
|
+
# client id is not required
|
15
|
+
client_id = data.client_id || 'default'
|
16
|
+
|
14
17
|
resource_from_existing_devise_user
|
15
|
-
return resource if correct_resource_type_logged_in?
|
18
|
+
return resource if correct_resource_type_logged_in? &&
|
19
|
+
resource_does_not_have_client_token?(client_id)
|
16
20
|
|
17
21
|
return nil unless data.token_prerequisites_present?
|
18
22
|
load_user_from_uid
|
@@ -42,5 +46,9 @@ module GrapeDeviseTokenAuth
|
|
42
46
|
def correct_resource_type_logged_in?
|
43
47
|
resource && resource.class == resource_class
|
44
48
|
end
|
49
|
+
|
50
|
+
def resource_does_not_have_client_token?(client_id)
|
51
|
+
resource.tokens[client_id].nil?
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_devise_token_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Cordell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,9 +128,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.2.2
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Allows an existing devise_token_auth/rails project to authenticate a Grape
|
135
135
|
API
|
136
136
|
test_files: []
|
137
|
+
has_rdoc:
|