devise_token_auth 0.1.27 → 0.1.28.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5c29b93ff06ca8cc30fdd3deffb09a913a047f2
4
- data.tar.gz: bd35baa78de384a098d7e27bc19ac3670c49c373
3
+ metadata.gz: 5b99f8dae62f960788af8b108ab370e420a54291
4
+ data.tar.gz: ddad0d672de28b386c09c2384bbec83d9acd5efe
5
5
  SHA512:
6
- metadata.gz: 9e8bfe5cbcb0ab772824ba30605d8cff0013eaa7ef0442aca020f9a88149e7d9b78a3e388f62d95bd30277194ae575d9061713592b3046bc7b7bab52efbe2dc3
7
- data.tar.gz: 200d1973c8dc02826de98b4406af9d7eeb42bf977471ce546061577bfb5d107578f3cab6fafd62e112e0a6557849883cd1a389f8ae1ab051bc405b2adf9ab6a7
6
+ metadata.gz: f7dca0bf0da13694fd383a38052d6da35d376597dc649a218b04d984a74c56b71c2c299b6a72c8b923a0b240392f3233f64f10dae27139884e92934ec5288a51
7
+ data.tar.gz: 1bf8004bfc4de1e9d74ea228b97770f30a969f3606321868cb8bd573c87c10658c9e87db3e147ade029838ee019b25d94b014fc92fcdd0379fcc2a00f22bcf04
data/README.md CHANGED
@@ -36,7 +36,7 @@ This project leverages the following gems:
36
36
  Add the following to your `Gemfile`:
37
37
 
38
38
  ~~~ruby
39
- gem devise_token_auth
39
+ gem 'devise_token_auth'
40
40
  ~~~
41
41
 
42
42
  Then install the gem using bundle:
@@ -1,5 +1,5 @@
1
1
  module DeviseTokenAuth
2
- class ApplicationController < ActionController::Base
2
+ class ApplicationController < DeviseController
3
3
  include DeviseTokenAuth::Concerns::SetUserByToken
4
4
  end
5
5
  end
@@ -21,11 +21,9 @@ module DeviseTokenAuth
21
21
  end
22
22
 
23
23
  def omniauth_success
24
- # pull resource class from omniauth return
25
- resource = request.env['omniauth.params']['resource_class'].constantize
26
24
 
27
25
  # find or create user by provider and provider uid
28
- @user = resource.where({
26
+ @user = resource_name.where({
29
27
  uid: auth_hash['uid'],
30
28
  provider: auth_hash['provider']
31
29
  }).first_or_initialize
@@ -61,6 +59,10 @@ module DeviseTokenAuth
61
59
  email: auth_hash['info']['email']
62
60
  })
63
61
 
62
+ # assign any additional (whitelisted) attributes
63
+ extra_params = whitelisted_params
64
+ @user.assign_attributes(extra_params) if extra_params
65
+
64
66
  # don't send confirmation email!!!
65
67
  @user.skip_confirmation!
66
68
 
@@ -84,6 +86,32 @@ module DeviseTokenAuth
84
86
  request.env['omniauth.auth']
85
87
  end
86
88
 
89
+ def whitelisted_params
90
+ whitelist = devise_parameter_sanitizer.for(:sign_up)
91
+
92
+ whitelist.inject({}){|coll, key|
93
+ param = request.env['omniauth.params'][key.to_s]
94
+ if param
95
+ coll[key] = param
96
+ end
97
+ coll
98
+ }
99
+ end
100
+
101
+ def devise_controller?
102
+ true
103
+ end
104
+
105
+ # pull resource class from omniauth return
106
+ def resource_name
107
+ request.env['omniauth.params']['resource_class'].constantize
108
+ end
109
+
110
+ # necessary for access to devise_parameter_sanitizers
111
+ def devise_mapping
112
+ Devise.mappings[request.env['omniauth.params']['resource_class'].underscore.to_sym]
113
+ end
114
+
87
115
  def generate_url(url, params = {})
88
116
  uri = URI(url)
89
117
  uri.query = params.to_query
@@ -1,3 +1,3 @@
1
1
  module DeviseTokenAuth
2
- VERSION = "0.1.27"
2
+ VERSION = "0.1.28.beta1"
3
3
  end
@@ -57,6 +57,32 @@ class OmniauthTest < ActionDispatch::IntegrationTest
57
57
  assert_equal User, @user.class
58
58
  end
59
59
  end
60
+
61
+ describe 'pass additional params' do
62
+ before do
63
+ @fav_color = 'alizarin crimson'
64
+ @unpermitted_param = "M. Bison"
65
+ get_via_redirect '/auth/facebook', {
66
+ auth_origin_url: @redirect_url,
67
+ favorite_color: @fav_color,
68
+ name: @unpermitted_param
69
+ }
70
+
71
+ @user = assigns(:user)
72
+ end
73
+
74
+ test 'status shows success' do
75
+ assert_equal 200, response.status
76
+ end
77
+
78
+ test 'additional attribute was passed' do
79
+ assert_equal @fav_color, @user.favorite_color
80
+ end
81
+
82
+ test 'non-whitelisted attributes are ignored' do
83
+ refute_equal @unpermitted_param, @user.name
84
+ end
85
+ end
60
86
  end
61
87
 
62
88
 
@@ -60,7 +60,7 @@ module ApplicationHelper
60
60
  "Beaver",
61
61
  "Beige",
62
62
  "B'dazzled blue",
63
- "Big dip oruby",
63
+ "Big dip o'ruby",
64
64
  "Bisque",
65
65
  "Bistre",
66
66
  "Bistre brown",
@@ -134,8 +134,8 @@ module ApplicationHelper
134
134
  "Cadmium orange",
135
135
  "Cadmium red",
136
136
  "Cadmium yellow",
137
- "Café au lait",
138
- "Café noir",
137
+ "Cafe au lait",
138
+ "Cafe noir",
139
139
  "Cal Poly Pomona green",
140
140
  "Cambridge Blue",
141
141
  "Camel",
@@ -422,7 +422,7 @@ module ApplicationHelper
422
422
  "Grizzly",
423
423
  "Grullo",
424
424
  "Guppie green",
425
- "Halayà úbe",
425
+ "Halaya ube",
426
426
  "Han blue",
427
427
  "Han purple",
428
428
  "Hansa yellow",
@@ -955,7 +955,7 @@ module ApplicationHelper
955
955
  "Teal deer",
956
956
  "Teal green",
957
957
  "Telemagenta",
958
- "Tenné",
958
+ "Tenne",
959
959
  "Terra cotta",
960
960
  "Thistle",
961
961
  "Thulian pink",
Binary file
Binary file