質問編集履歴

6

タイポ

2022/09/02 03:15

投稿

hakka
hakka

スコア15

test CHANGED
File without changes
test CHANGED
@@ -1,116 +1,118 @@
1
1
  ##deviseでfacebookユーザー認証がうまく機能していない
2
-
3
-
4
2
 
5
3
  導入したはじめは,facebookで登録するのボタンを押してみると、ちゃんとfacebookAPI側のページ切り変わって、ごの名前で続けますか?みたいなところまでは表示されました。
6
4
 
7
-
8
-
9
5
  問題はそのあとなのですが、それ以降ボタンを押しても、なんの反応もしなくなりました。まして、databaseの中を確認してもユーザーが追加されているわけでもありませんでした。
10
-
11
-
12
6
 
13
7
  gitのチュートリアルをみて進めました。
14
8
 
15
-
16
-
17
9
  サーバーの反応
18
-
19
10
  ```ここに言語を入力
20
-
21
11
  Started GET "/users/sign_up" for 127.0.0.1 at 2017-05-18 10:18:13 +0900
22
-
23
12
  Processing by Devise::RegistrationsController#new as HTML
24
-
25
13
  Rendering devise/registrations/new.html.erb within layouts/application
26
-
27
14
  Rendered partial/_navbar.html.erb (1.6ms) [cache miss]
28
-
29
15
  Rendered partial/_deviseErrorMsg.html.erb (1.3ms) [cache miss]
30
-
31
16
  Rendered devise/shared/_links.html.erb (1.4ms) [cache miss]
32
-
33
17
  Rendered devise/registrations/new.html.erb within layouts/application (35.9ms)
34
-
35
18
  Completed 200 OK in 92ms (Views: 91.0ms | ActiveRecord: 0.0ms)
36
19
 
37
20
 
21
+ Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
22
+ I, [2017-05-18T10:18:14.217859 #54438] INFO -- omniauth: (facebook) Request phase initiated.
23
+ Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
24
+ I, [2017-05-18T10:18:14.719085 #54438] INFO -- omniauth: (facebook) Request phase initiated.
25
+ Started GET "/users/auth/facebook/callback?code=AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_&state=d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
26
+ I, [2017-05-18T10:18:14.916662 #54438] INFO -- omniauth: (facebook) Callback phase initiated.
27
+ Processing by Users::OmniauthCallbacksController#facebook as HTML
28
+ Parameters: {"code"=>"AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_", "state"=>"d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114"}
29
+ User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."provider" = ? AND "users"."uid" = ? ORDER BY "users"."id" ASC LIMIT ? [["provider", "facebook"], ["uid", "1777251139255645"], ["LIMIT", 1]]
30
+ (0.1ms) begin transaction
31
+ User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ? [["email"], ["LIMIT", 1]]
32
+ (0.1ms) rollback transaction
33
+ Redirected to http://localhost:3000/users/sign_up
34
+ Completed 302 Found in 184ms (ActiveRecord: 1.1ms)
35
+ ```
36
+
37
+ コントローラーの内容
38
+ ```ここに言語を入力
39
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
40
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
41
+ def facebook
42
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
43
+ @user = User.from_omniauth(request.env["omniauth.auth"])
44
+
45
+ if @user.persisted?
46
+ sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
47
+ set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
48
+ else
49
+ session["devise.facebook_data"] = request.env["omniauth.auth"]
50
+ redirect_to new_user_registration_url
51
+ end
52
+ end
53
+
54
+ def failure
55
+ redirect_to root_path
56
+ end
57
+ end
58
+ end
59
+ ```
38
60
 
39
61
 
40
-
41
- Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
42
-
43
- I, [2017-05-18T10:18:14.217859 #54438] INFO -- omniauth: (facebook) Request phase initiated.
44
-
45
- Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
46
-
47
- I, [2017-05-18T10:18:14.719085 #54438] INFO -- omniauth: (facebook) Request phase initiated.
48
-
49
- Started GET "/users/auth/facebook/callback?code=AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_&state=d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
50
-
51
- I, [2017-05-18T10:18:14.916662 #54438] INFO -- omniauth: (facebook) Callback phase initiated.
52
-
53
- Processing by Users::OmniauthCallbacksController#facebook as HTML
54
-
55
- Parameters: {"code"=>"AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_", "state"=>"d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114"}
56
-
57
- User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."provider" = ? AND "users"."uid" = ? ORDER BY "users"."id" ASC LIMIT ? [["provider", "facebook"], ["uid", "1777251139255645"], ["LIMIT", 1]]
58
-
59
- (0.1ms) begin transaction
60
-
61
- User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "xxryujixx282@gmail.com"], ["LIMIT", 1]]
62
-
63
- (0.1ms) rollback transaction
64
-
65
- Redirected to http://localhost:3000/users/sign_up
66
-
67
- Completed 302 Found in 184ms (ActiveRecord: 1.1ms)
68
-
62
+ ##設定一覧
63
+ gem
64
+ ```ここに言語を入力
65
+ gem 'rails', '~> 5.1.0'
66
+ gem 'sqlite3'
67
+ gem 'puma', '~> 3.7'
68
+ gem 'sass-rails', '~> 5.0'
69
+ gem 'uglifier', '>= 1.3.0'
70
+ gem 'coffee-rails', '~> 4.2'
71
+ gem 'turbolinks', '~> 5'
72
+ gem 'jbuilder', '~> 2.5'
73
+ gem 'bootstrap-sass'
74
+ gem 'autoprefixer-rails'
75
+ gem 'devise'
76
+ gem 'jquery-rails'
77
+ gem 'jquery-ui-rails'
78
+ gem 'toastr-rails'
79
+ gem 'omniauth-facebook'
80
+ gem 'actionpack-page_caching'
69
81
  ```
70
82
 
71
83
 
72
84
 
73
- コントローラーの内容
85
+ devise.rb
86
+ ```
74
87
 
75
- ```ここに言語を入力
88
+ # ==> OmniAuth
89
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
90
+ # up on your models and hooks.
91
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
76
92
 
93
+ # ==> Warden configuration
94
+ # If you want to use other strategies, that are not supported by Devise, or
77
- class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
95
+ # change the failure app, you can configure them inside the config.warden block.
96
+ #
97
+ # config.warden do |manager|
98
+ # manager.intercept_401 = false
99
+ # manager.default_strategies(scope: :user).unshift :some_external_strategy
100
+ # end
78
101
 
102
+ # ==> Mountable engine configurations
103
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
104
+ # is mountable, there are some extra configurations to be taken into account.
105
+ # The following options are available, assuming the engine is mounted as:
106
+ #
107
+ # mount MyEngine, at: '/my_engine'
108
+ #
109
+ # The router that invoked `devise_for`, in the example above, would be:
110
+ # config.router_name = :my_engine
111
+ #
79
- class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
112
+ # When using OmniAuth, Devise cannot automatically set OmniAuth path,
80
-
81
- def facebook
113
+ # so you need to do it manually. For the users scope, it would be:
82
-
83
- # You need to implement the method below in your model (e.g. app/models/user.rb)
114
+ # config.omniauth_path_prefix = '/my_engine/users/auth'
84
-
85
- @user = User.from_omniauth(request.env["omniauth.auth"])
86
-
87
-
88
-
89
- if @user.persisted?
90
-
91
- sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
92
-
93
- set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
115
+ config.omniauth :facebook, "419987595054517", "ae3d9fae963284ede5abeec3b9784850", scope: 'email', info_fields: 'email,name'
94
-
95
- else
96
-
97
- session["devise.facebook_data"] = request.env["omniauth.auth"]
98
-
99
- redirect_to new_user_registration_url
100
-
101
- end
102
-
103
- end
104
-
105
-
106
-
107
- def failure
108
-
109
- redirect_to root_path
110
-
111
- end
112
-
113
- end
114
116
 
115
117
  end
116
118
 
@@ -119,153 +121,16 @@
119
121
 
120
122
 
121
123
 
122
-
123
- ##設定一覧
124
-
125
- gem
126
-
127
- ```ここに言語を入力
128
-
129
- gem 'rails', '~> 5.1.0'
130
-
131
- gem 'sqlite3'
132
-
133
- gem 'puma', '~> 3.7'
134
-
135
- gem 'sass-rails', '~> 5.0'
136
-
137
- gem 'uglifier', '>= 1.3.0'
138
-
139
- gem 'coffee-rails', '~> 4.2'
140
-
141
- gem 'turbolinks', '~> 5'
142
-
143
- gem 'jbuilder', '~> 2.5'
144
-
145
- gem 'bootstrap-sass'
146
-
147
- gem 'autoprefixer-rails'
148
-
149
- gem 'devise'
150
-
151
- gem 'jquery-rails'
152
-
153
- gem 'jquery-ui-rails'
154
-
155
- gem 'toastr-rails'
156
-
157
- gem 'omniauth-facebook'
158
-
159
- gem 'actionpack-page_caching'
160
-
161
- ```
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
- devise.rb
170
-
171
- ```
172
-
173
-
174
-
175
- # ==> OmniAuth
176
-
177
- # Add a new OmniAuth provider. Check the wiki for more information on setting
178
-
179
- # up on your models and hooks.
180
-
181
- # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
182
-
183
-
184
-
185
- # ==> Warden configuration
186
-
187
- # If you want to use other strategies, that are not supported by Devise, or
188
-
189
- # change the failure app, you can configure them inside the config.warden block.
190
-
191
- #
192
-
193
- # config.warden do |manager|
194
-
195
- # manager.intercept_401 = false
196
-
197
- # manager.default_strategies(scope: :user).unshift :some_external_strategy
198
-
199
- # end
200
-
201
-
202
-
203
- # ==> Mountable engine configurations
204
-
205
- # When using Devise inside an engine, let's call it `MyEngine`, and this engine
206
-
207
- # is mountable, there are some extra configurations to be taken into account.
208
-
209
- # The following options are available, assuming the engine is mounted as:
210
-
211
- #
212
-
213
- # mount MyEngine, at: '/my_engine'
214
-
215
- #
216
-
217
- # The router that invoked `devise_for`, in the example above, would be:
218
-
219
- # config.router_name = :my_engine
220
-
221
- #
222
-
223
- # When using OmniAuth, Devise cannot automatically set OmniAuth path,
224
-
225
- # so you need to do it manually. For the users scope, it would be:
226
-
227
- # config.omniauth_path_prefix = '/my_engine/users/auth'
228
-
229
- config.omniauth :facebook, "419987595054517", "ae3d9fae963284ede5abeec3b9784850", scope: 'email', info_fields: 'email,name'
230
-
231
-
232
-
233
- end
234
-
235
-
236
-
237
- ```
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
124
  routes.rb
248
-
249
125
  ```ここに言語を入
250
-
251
126
  Rails.application.routes.draw do
252
127
 
253
-
254
-
255
128
  root :to => 'pages#index'
256
-
257
-
258
129
 
259
130
  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
260
131
 
261
132
 
262
133
 
263
-
264
-
265
-
266
-
267
134
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
268
-
269
135
  end
270
-
271
136
  ```

5

修正

2017/05/18 05:27

投稿

hakka
hakka

スコア15

test CHANGED
File without changes
test CHANGED
@@ -70,7 +70,7 @@
70
70
 
71
71
 
72
72
 
73
- ##コントローラーの内容
73
+ コントローラーの内容
74
74
 
75
75
  ```ここに言語を入力
76
76
 

4

コード修正

2017/05/18 05:26

投稿

hakka
hakka

スコア15

test CHANGED
File without changes
test CHANGED
@@ -70,6 +70,52 @@
70
70
 
71
71
 
72
72
 
73
+ ##コントローラーの内容
74
+
75
+ ```ここに言語を入力
76
+
77
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
78
+
79
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
80
+
81
+ def facebook
82
+
83
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
84
+
85
+ @user = User.from_omniauth(request.env["omniauth.auth"])
86
+
87
+
88
+
89
+ if @user.persisted?
90
+
91
+ sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
92
+
93
+ set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
94
+
95
+ else
96
+
97
+ session["devise.facebook_data"] = request.env["omniauth.auth"]
98
+
99
+ redirect_to new_user_registration_url
100
+
101
+ end
102
+
103
+ end
104
+
105
+
106
+
107
+ def failure
108
+
109
+ redirect_to root_path
110
+
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+
117
+ ```
118
+
73
119
 
74
120
 
75
121
 

3

誤字

2017/05/18 05:26

投稿

hakka
hakka

スコア15

test CHANGED
File without changes
test CHANGED
@@ -12,8 +12,6 @@
12
12
 
13
13
  gitのチュートリアルをみて進めました。
14
14
 
15
- とくにrails sでエラーがでるわけでもありません。
16
-
17
15
 
18
16
 
19
17
  サーバーの反応

2

コード追加

2017/05/18 01:19

投稿

hakka
hakka

スコア15

test CHANGED
File without changes
test CHANGED
@@ -16,6 +16,64 @@
16
16
 
17
17
 
18
18
 
19
+ サーバーの反応
20
+
21
+ ```ここに言語を入力
22
+
23
+ Started GET "/users/sign_up" for 127.0.0.1 at 2017-05-18 10:18:13 +0900
24
+
25
+ Processing by Devise::RegistrationsController#new as HTML
26
+
27
+ Rendering devise/registrations/new.html.erb within layouts/application
28
+
29
+ Rendered partial/_navbar.html.erb (1.6ms) [cache miss]
30
+
31
+ Rendered partial/_deviseErrorMsg.html.erb (1.3ms) [cache miss]
32
+
33
+ Rendered devise/shared/_links.html.erb (1.4ms) [cache miss]
34
+
35
+ Rendered devise/registrations/new.html.erb within layouts/application (35.9ms)
36
+
37
+ Completed 200 OK in 92ms (Views: 91.0ms | ActiveRecord: 0.0ms)
38
+
39
+
40
+
41
+
42
+
43
+ Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
44
+
45
+ I, [2017-05-18T10:18:14.217859 #54438] INFO -- omniauth: (facebook) Request phase initiated.
46
+
47
+ Started GET "/users/auth/facebook" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
48
+
49
+ I, [2017-05-18T10:18:14.719085 #54438] INFO -- omniauth: (facebook) Request phase initiated.
50
+
51
+ Started GET "/users/auth/facebook/callback?code=AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_&state=d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114" for 127.0.0.1 at 2017-05-18 10:18:14 +0900
52
+
53
+ I, [2017-05-18T10:18:14.916662 #54438] INFO -- omniauth: (facebook) Callback phase initiated.
54
+
55
+ Processing by Users::OmniauthCallbacksController#facebook as HTML
56
+
57
+ Parameters: {"code"=>"AQBgPbgvBmdBdpXERIXf-GYr9ZQXAQzrSx7xvz2NNk1GFKzzC0-lYY-vgn8ibzoR6gfflCvvnIIevyfk5RHp5C0FVW2U_ub1B3CQjribETL_vCerVBJVUy7VnbcGpbBM2Ucik8ZzWC2z0E8DwJZ6J4qrPl51eMNeoZb6fA-937twgZkbZ6uNnrfPVfVGudDebdojDareiTrkh5i_dXdz29JmTZ4J5PM7MctcuITXUdvShQp3aZoMmhN8uAjP8nSu4FSuT-_2xTo_OtutVHG-GuRLH8xggp30OgKovp-ZRsVFieK9_SyN4aC6E3vWeAUMigiHEdjqeWGRJpb9v2R7Xt2_", "state"=>"d801e6f1ad665c35b4e409138f2a31ec46e49e9961be8114"}
58
+
59
+ User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."provider" = ? AND "users"."uid" = ? ORDER BY "users"."id" ASC LIMIT ? [["provider", "facebook"], ["uid", "1777251139255645"], ["LIMIT", 1]]
60
+
61
+ (0.1ms) begin transaction
62
+
63
+ User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "xxryujixx282@gmail.com"], ["LIMIT", 1]]
64
+
65
+ (0.1ms) rollback transaction
66
+
67
+ Redirected to http://localhost:3000/users/sign_up
68
+
69
+ Completed 302 Found in 184ms (ActiveRecord: 1.1ms)
70
+
71
+ ```
72
+
73
+
74
+
75
+
76
+
19
77
 
20
78
 
21
79
  ##設定一覧

1

段落修正

2017/05/18 01:19

投稿

hakka
hakka

スコア15

test CHANGED
File without changes
test CHANGED
@@ -66,7 +66,7 @@
66
66
 
67
67
  devise.rb
68
68
 
69
- ```ここに言語を入力
69
+ ```
70
70
 
71
71
 
72
72
 
@@ -142,7 +142,9 @@
142
142
 
143
143
 
144
144
 
145
+ routes.rb
146
+
145
- routes.rb```ここに言語を入
147
+ ```ここに言語を入
146
148
 
147
149
  Rails.application.routes.draw do
148
150