質問編集履歴

2

追記

2019/03/09 04:04

投稿

m.m.
m.m.

スコア8

test CHANGED
File without changes
test CHANGED
@@ -132,6 +132,28 @@
132
132
 
133
133
  ```
134
134
 
135
+
136
+
137
+
138
+
139
+ config/services.php
140
+
141
+ ```
142
+
143
+ 'google' => [
144
+
145
+ 'client_id' => env('**********************************************************'),
146
+
147
+ 'client_secret' => env('*************************'),
148
+
149
+ 'redirect' => env('**************************'),
150
+
151
+ ],
152
+
153
+ ```
154
+
155
+
156
+
135
157
  config/app.php
136
158
 
137
159
  ```

1

追記

2019/03/09 04:04

投稿

m.m.
m.m.

スコア8

test CHANGED
File without changes
test CHANGED
@@ -12,26 +12,28 @@
12
12
 
13
13
  でOAuth認証を実装しようと考え、下記サイトを参考にしました。
14
14
 
15
-
15
+ ```
16
16
 
17
17
  https://leben.mobi/blog/laravel5_social_login/php/
18
18
 
19
-
19
+ ```
20
20
 
21
21
  一通りサイトに習いコードを記述しましたが、ソーシャルボタンを押下時に下記エラーが発生します。
22
22
 
23
-
23
+ ```
24
24
 
25
25
  Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
26
26
 
27
27
  Argument 1 passed to Laravel\Socialite\SocialiteManager::formatRedirectUrl() must be of the type array, null given, called in C:\xampp\htdocs\demo\vendor\laravel\socialite\src\SocialiteManager.php on line 126
28
28
 
29
-
29
+ ```
30
30
 
31
31
  エラー箇所は下記のようです。
32
32
 
33
33
  C:\xampp\htdocs\demo\vendor\laravel\socialite\src\SocialiteManager.php
34
34
 
35
+ ```
36
+
35
37
  *
36
38
 
37
39
  * @param array $config
@@ -98,8 +100,242 @@
98
100
 
99
101
  *
100
102
 
101
-
103
+ ```
102
104
 
103
105
  原因がわからず困っております。
104
106
 
105
107
  ご教授よろしくお願いします。
108
+
109
+
110
+
111
+ 追記:
112
+
113
+ SocialiteManager.php 126行付近
114
+
115
+ ```
116
+
117
+ public function buildProvider($provider, $config)
118
+
119
+ {
120
+
121
+ return new $provider(
122
+
123
+ $this->app['request'], $config['client_id'],
124
+
125
+ $config['client_secret'], $this->formatRedirectUrl($config),
126
+
127
+ Arr::get($config, 'guzzle', [])
128
+
129
+ );
130
+
131
+ }
132
+
133
+ ```
134
+
135
+ config/app.php
136
+
137
+ ```
138
+
139
+ 'providers' => [
140
+
141
+ Laravel\Socialite\SocialiteServiceProvider::class,
142
+
143
+ ],
144
+
145
+ 'aliases' => [
146
+
147
+ 'Socialite' => Laravel\Socialite\Facades\Socialite::class,
148
+
149
+ ],
150
+
151
+ ```
152
+
153
+
154
+
155
+ Auth/LoginController.php
156
+
157
+ ```
158
+
159
+ <?php
160
+
161
+
162
+
163
+ namespace App\Http\Controllers\Auth;
164
+
165
+
166
+
167
+ use Illuminate\Http\Request;
168
+
169
+ use App\Http\Controllers\Controller;
170
+
171
+ use Illuminate\Foundation\Auth\AuthenticatesUsers;
172
+
173
+ use App\Events\Logined;
174
+
175
+ use Socialite;
176
+
177
+ use App\User;
178
+
179
+ use Auth;
180
+
181
+
182
+
183
+
184
+
185
+ class LoginController extends Controller
186
+
187
+ {
188
+
189
+ /*
190
+
191
+ |--------------------------------------------------------------------------
192
+
193
+ | Login Controller
194
+
195
+ |--------------------------------------------------------------------------
196
+
197
+ |
198
+
199
+ | This controller handles authenticating users for the application and
200
+
201
+ | redirecting them to your home screen. The controller uses a trait
202
+
203
+ | to conveniently provide its functionality to your applications.
204
+
205
+ |
206
+
207
+ */
208
+
209
+
210
+
211
+ use AuthenticatesUsers;
212
+
213
+ protected $maxAttempts = 2; // ログイン試行回数(回)
214
+
215
+ protected $decayMinutes = 10; // ログインロックタイム(分)
216
+
217
+ /**
218
+
219
+ * Where to redirect users after login.
220
+
221
+ *
222
+
223
+ * @var string
224
+
225
+ */
226
+
227
+ protected $redirectTo = '/verified';
228
+
229
+
230
+
231
+ /**
232
+
233
+ * Create a new controller instance.
234
+
235
+ *
236
+
237
+ * @return void
238
+
239
+ */
240
+
241
+ public function __construct()
242
+
243
+ {
244
+
245
+ $this->middleware('guest')->except('logout');
246
+
247
+ }
248
+
249
+
250
+
251
+ /**
252
+
253
+ * ログイン認証後の処理
254
+
255
+ * @param Request $request
256
+
257
+ * @param $user
258
+
259
+ */
260
+
261
+ protected function authenticated(Request $request, $user)
262
+
263
+ {
264
+
265
+ // ログインイベントを発火させ最終ログイン日時を記録する
266
+
267
+ event(new Logined());
268
+
269
+ }
270
+
271
+
272
+
273
+ public function username()
274
+
275
+ {
276
+
277
+ return 'userid';
278
+
279
+ }
280
+
281
+
282
+
283
+ /**
284
+
285
+ * Handle Social login request
286
+
287
+ *
288
+
289
+ * @return response
290
+
291
+ */
292
+
293
+
294
+
295
+ public function socialLogin($social)
296
+
297
+ {
298
+
299
+ return Socialite::driver($social)->redirect();
300
+
301
+ }
302
+
303
+
304
+
305
+ /**
306
+
307
+ * Obtain the user information from Social Logged in.
308
+
309
+ * @param $social
310
+
311
+ * @return Response
312
+
313
+ */
314
+
315
+
316
+
317
+ public function handleProviderCallback($social)
318
+
319
+ {
320
+
321
+ $userSocial = Socialite::driver($social)->user();
322
+
323
+ $user = User::where(['email' => $userSocial->getEmail()])->first();
324
+
325
+ if($user){
326
+
327
+ Auth::login($user);
328
+
329
+ return redirect()->action('HomeController@index');
330
+
331
+ }else{
332
+
333
+ return view('auth.register',['name' => $userSocial->getName(), 'email' => $userSocial->getEmail()]);
334
+
335
+ }
336
+
337
+ }
338
+
339
+ }
340
+
341
+ ```