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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35ce7f0b222561a9d13f206c77ecbb509ddcfbad
4
- data.tar.gz: 71300758c8f421b5700abf180286ab0a55b0ea15
3
+ metadata.gz: 20ce9019cdda54279d483b4e1d83494fff408872
4
+ data.tar.gz: d9f9365c4915ca9384124ed3d06e519ba33128d7
5
5
  SHA512:
6
- metadata.gz: 896fce5fc9694288093dd293fd9dbcf76409798889afea764fa97d79211eee1fa46e5da0beeddbe958d50e5c46a22411d45cd55d988649aad79b2ff432bfcc25
7
- data.tar.gz: 994295038c82feaa3b4137292ea76590827444dbeebc8885b05d3c7aed8e484da6b1d14a6991d893b7a9cedaacdf817bad6d9f9081196f0d39dfcdd63462b8a5
6
+ metadata.gz: 574a15895c934d5e7c309bff9021035016d40e650b00bd2e9cf25e3c88b4d6f52c9458d2b399cef2dffa4770a3568c5182b09fac845b113785c70944455bade8
7
+ data.tar.gz: f344a3e4e844587ffc6607e5d3f14b6af9d192033104e6a9fae97d4c65527a850ce9e7199be51e93306d5399d41fb69d21107a621bfee8bd3b225e8e35293e6a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,4 @@
1
- #Current - 0.1.2
1
+ #Current - 0.1
2
+ - Add a way to disable integration with warden
2
3
  - Adding a authentication helper that doesn't fail.
3
4
 
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  # GrapeDeviseTokenAuth
2
2
 
3
- GrapeDeviseTokenAuth gem is a compatability layer between
4
- [devise_token_auth][1] and [grape][2]. It is useful when mounting a grape API
5
- in a rails application where [devise][3] (or `devise_token_auth` + `devise`)
6
- is already present. It is reliant on `devise_token_auth` and `devise`,
7
- therefore it is not suitable for grape where these are not present.
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
- Hurley][4] and his fantistic [devise_token_auth][1] gem.
11
- I merely have ported this to work well with grape.
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
@@ -3,7 +3,7 @@ module GrapeDeviseTokenAuth
3
3
  extend Forwardable
4
4
 
5
5
  def initialize(warden, mapping, request_start, data)
6
- @resource = warden.session_serializer.fetch(mapping)
6
+ @resource = warden.user(:user)
7
7
  @request_start = request_start
8
8
  @data = data
9
9
  end
@@ -3,7 +3,7 @@ module GrapeDeviseTokenAuth
3
3
  def self.included(_base)
4
4
  Devise.mappings.keys.each do |mapping|
5
5
  define_method("current_#{mapping}") do
6
- warden.session_serializer.fetch(mapping)
6
+ warden.user(mapping)
7
7
  end
8
8
 
9
9
  define_method("authenticate_#{mapping}") do
@@ -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.session_serializer.store(resource, scope)
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
@@ -1,3 +1,3 @@
1
1
  module GrapeDeviseTokenAuth
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  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.2
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-09-09 00:00:00.000000000 Z
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.0.14
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: