|
16 | 16 | use Illuminate\Contracts\Encryption\Encrypter; |
17 | 17 | use Illuminate\Foundation\Auth\AuthenticatesUsers; |
18 | 18 | use Pterodactyl\Traits\Helpers\ProvidesJWTServices; |
| 19 | +use Pterodactyl\Transformers\Api\Client\AccountTransformer; |
19 | 20 | use Illuminate\Contracts\Cache\Repository as CacheRepository; |
20 | 21 | use Pterodactyl\Contracts\Repository\UserRepositoryInterface; |
21 | 22 |
|
@@ -137,25 +138,35 @@ protected function sendLoginResponse(User $user, Request $request): JsonResponse |
137 | 138 | $request->session()->regenerate(); |
138 | 139 | $this->clearLoginAttempts($request); |
139 | 140 |
|
140 | | - $token = $this->builder->setIssuer(config('app.url')) |
| 141 | + $this->auth->guard()->login($user, true); |
| 142 | + |
| 143 | + return response()->json([ |
| 144 | + 'complete' => true, |
| 145 | + 'intended' => $this->redirectPath(), |
| 146 | + 'jwt' => $this->createJsonWebToken($user), |
| 147 | + ]); |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Create a new JWT for the request and sign it using the signing key. |
| 152 | + * |
| 153 | + * @param User $user |
| 154 | + * @return string |
| 155 | + */ |
| 156 | + protected function createJsonWebToken(User $user): string |
| 157 | + { |
| 158 | + $token = $this->builder |
| 159 | + ->setIssuer('Pterodactyl Panel') |
141 | 160 | ->setAudience(config('app.url')) |
142 | | - ->setId(str_random(12), true) |
| 161 | + ->setId(str_random(16), true) |
143 | 162 | ->setIssuedAt(Chronos::now()->getTimestamp()) |
144 | 163 | ->setNotBefore(Chronos::now()->getTimestamp()) |
145 | 164 | ->setExpiration(Chronos::now()->addSeconds(config('session.lifetime'))->getTimestamp()) |
146 | | - ->set('user', $user->only([ |
147 | | - 'id', 'uuid', 'username', 'email', 'name_first', 'name_last', 'language', 'root_admin', |
148 | | - ])) |
| 165 | + ->set('user', (new AccountTransformer())->transform($user)) |
149 | 166 | ->sign($this->getJWTSigner(), $this->getJWTSigningKey()) |
150 | 167 | ->getToken(); |
151 | 168 |
|
152 | | - $this->auth->guard()->login($user, true); |
153 | | - |
154 | | - return response()->json([ |
155 | | - 'complete' => true, |
156 | | - 'intended' => $this->redirectPath(), |
157 | | - 'token' => $token->__toString(), |
158 | | - ]); |
| 169 | + return $token->__toString(); |
159 | 170 | } |
160 | 171 |
|
161 | 172 | /** |
|
0 commit comments