質問編集履歴

5

記述変更ご

2018/06/03 13:04

投稿

FigHy
FigHy

スコア19

test CHANGED
File without changes
test CHANGED
@@ -54,13 +54,33 @@
54
54
 
55
55
 
56
56
 
57
- 追記
57
+ 追記→変更後
58
-
59
-
60
-
58
+
59
+
60
+
61
- ```
61
+ ```
62
+
62
-
63
+ <?php
64
+
65
+
66
+
67
+ namespace App\Socialite;
68
+
69
+
70
+
71
+ use Laravel\Socialite\Two\AbstractProvider;
72
+
73
+ use Laravel\Socialite\Two\ProviderInterface;
74
+
75
+ use Laravel\Socialite\Two\User;
76
+
77
+
78
+
79
+ class LineProvider extends AbstractProvider implements ProviderInterface
80
+
81
+ {
82
+
63
- protected function getAuthUrl($state)
83
+ protected function getAuthUrl($state)
64
84
 
65
85
  {
66
86
 
@@ -90,15 +110,13 @@
90
110
 
91
111
  'headers' => [
92
112
 
93
- 'X-Line-ChannelToken' => $token,
113
+ 'Authorization' => 'Bearer '.$token,
94
114
 
95
115
  ],
96
116
 
97
117
  ]);
98
118
 
99
-
100
-
101
- return json_decode($response->getBody(), true);
119
+ return json_decode($response->getBody()->getContents(), true);
102
120
 
103
121
  }
104
122
 
@@ -110,11 +128,15 @@
110
128
 
111
129
  return (new User())->setRaw($user)->map([
112
130
 
131
+ 'id' => $user['userId'] ?? $user['sub'] ?? null,
132
+
133
+ 'nickname' => null,
134
+
135
+ 'name' => $user['displayName'] ?? $user['name'] ?? null,
136
+
137
+ 'avatar' => $user['pictureUrl'] ?? $user['picture'] ?? null,
138
+
113
- 'id' => $user['mid'],
139
+ 'email' => $user['email'] ?? null,
114
-
115
- 'name' => $user['displayName'],
116
-
117
- 'avatar' => $user['pictureUrl'],
118
140
 
119
141
  ]);
120
142
 
@@ -126,20 +148,66 @@
126
148
 
127
149
  {
128
150
 
129
- return [
130
-
131
- 'client_id' => $this->clientId,
132
-
133
- 'client_secret' => $this->clientSecret,
134
-
135
- 'code' => $code,
136
-
137
- 'redirect_uri' => $this->redirectUrl,
151
+ return array_merge(parent::getTokenFields($code), [
138
-
152
+
139
- 'grant_type' => 'authorization_code',
153
+ 'grant_type' => 'authorization_code',
140
-
154
+
141
- ];
155
+ ]);
142
-
156
+
143
- }
157
+ }
158
+
159
+
160
+
144
-
161
+ /**
162
+
163
+ * @return \SocialiteProviders\Manager\OAuth2\User
164
+
165
+ */
166
+
167
+ public function user()
168
+
169
+ {
170
+
171
+ if ($this->hasInvalidState()) {
172
+
173
+ throw new InvalidStateException();
174
+
175
+ }
176
+
177
+ $response = $this->getAccessTokenResponse($this->getCode());
178
+
179
+ if ($jwt = $response['id_token'] ?? null) {
180
+
181
+ list($headb64, $bodyb64, $cryptob64) = explode('.', $jwt);
182
+
183
+ $user = $this->mapUserToObject(json_decode(base64_decode($bodyb64), true));
184
+
185
+ } else {
186
+
187
+ $user = $this->mapUserToObject($this->getUserByToken(
188
+
189
+ $token = $this->parseAccessToken($response)
190
+
191
+ ));
192
+
193
+ }
194
+
195
+ $this->credentialsResponseBody = $response;
196
+
197
+ if ($user instanceof User) {
198
+
199
+ $user->setAccessTokenResponseBody($this->credentialsResponseBody);
200
+
201
+ }
202
+
203
+ return $user->setToken($this->parseAccessToken($response))
204
+
205
+ ->setRefreshToken($this->parseRefreshToken($response))
206
+
207
+ ->setExpiresIn($this->parseExpiresIn($response));
208
+
209
+ }
210
+
211
+ }
212
+
145
- ```
213
+ ```

4

2018/06/03 13:04

投稿

FigHy
FigHy

スコア19

test CHANGED
@@ -1 +1 @@
1
- Laravel Line ログイン認証機能でのエラー
1
+ Laravel Line Socialite ログイン認証機能でのエラー
test CHANGED
File without changes

3

エラー文追加

2018/06/03 04:49

投稿

FigHy
FigHy

スコア19

test CHANGED
File without changes
test CHANGED
@@ -8,9 +8,19 @@
8
8
 
9
9
 
10
10
 
11
+ エラー文
12
+
11
13
  ```
12
14
 
13
15
  Client error: `POST https://api.line.me/oauth2/v2.1/token` resulted in a `400 Bad Request` response: {"error":"invalid_request","error_description":"code is required."}
16
+
17
+ ```
18
+
19
+ エラー箇所
20
+
21
+ ```
22
+
23
+ return new $className($message, $request, $response, $previous, $ctx);
14
24
 
15
25
  ```
16
26
 

2

リクエスト追記

2018/06/03 00:03

投稿

FigHy
FigHy

スコア19

test CHANGED
File without changes
test CHANGED
@@ -41,3 +41,95 @@
41
41
 
42
42
 
43
43
  ご教授お願い致します。
44
+
45
+
46
+
47
+ 追記
48
+
49
+
50
+
51
+ ```
52
+
53
+ protected function getAuthUrl($state)
54
+
55
+ {
56
+
57
+ return $this->buildAuthUrlFromBase('https://access.line.me/oauth2/v2.1/authorize', $state);
58
+
59
+ }
60
+
61
+
62
+
63
+ protected function getTokenUrl()
64
+
65
+ {
66
+
67
+ return 'https://api.line.me/oauth2/v2.1/token';
68
+
69
+
70
+
71
+ }
72
+
73
+
74
+
75
+ protected function getUserByToken($token)
76
+
77
+ {
78
+
79
+ $response = $this->getHttpClient()->get('https://api.line.me/v2/profile', [
80
+
81
+ 'headers' => [
82
+
83
+ 'X-Line-ChannelToken' => $token,
84
+
85
+ ],
86
+
87
+ ]);
88
+
89
+
90
+
91
+ return json_decode($response->getBody(), true);
92
+
93
+ }
94
+
95
+
96
+
97
+ protected function mapUserToObject(array $user)
98
+
99
+ {
100
+
101
+ return (new User())->setRaw($user)->map([
102
+
103
+ 'id' => $user['mid'],
104
+
105
+ 'name' => $user['displayName'],
106
+
107
+ 'avatar' => $user['pictureUrl'],
108
+
109
+ ]);
110
+
111
+ }
112
+
113
+
114
+
115
+ protected function getTokenFields($code)
116
+
117
+ {
118
+
119
+ return [
120
+
121
+ 'client_id' => $this->clientId,
122
+
123
+ 'client_secret' => $this->clientSecret,
124
+
125
+ 'code' => $code,
126
+
127
+ 'redirect_uri' => $this->redirectUrl,
128
+
129
+ 'grant_type' => 'authorization_code',
130
+
131
+ ];
132
+
133
+ }
134
+
135
+ ```

1

タイトル変更

2018/06/02 23:56

投稿

FigHy
FigHy

スコア19

test CHANGED
@@ -1 +1 @@
1
- Laravel Line ログイン
1
+ Laravel Line ログイン認証機能でのエラー
test CHANGED
File without changes