Skip to content

Commit

Permalink
🔥 Remove API login endpoint
Browse files Browse the repository at this point in the history
closes #1772
  • Loading branch information
MrKrisKrisu committed Sep 22, 2023
1 parent 6eacbd1 commit e827380
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
28 changes: 3 additions & 25 deletions app/Http/Controllers/API/v1/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers\API\v1;

use App\Http\Controllers\Backend\Auth\LoginController;
use App\Http\Resources\UserSettingsResource;
use App\Providers\AuthServiceProvider;
use Illuminate\Http\JsonResponse;
Expand All @@ -11,28 +10,6 @@
class AuthController extends Controller
{

/**
* @param Request $request
*
* @return JsonResponse
* @deprecated Remove before 2023-10! Maybe earlier - if possible. Deprecation is already announced since
* November'22.
*/
public function login(Request $request): JsonResponse {
$validated = $request->validate(['login' => ['required', 'max:255'], 'password' => ['required', 'min:8', 'max:255']]);

if (LoginController::login($validated['login'], $validated['password'])) {
$token = $request->user()->createToken('token', array_keys(AuthServiceProvider::$scopes));
return $this->sendResponse([
'WARNING' => 'This endpoint (login) is deprecated and will be removed in the following weeks. Please migrate to use OAuth2. More information: https://github.com/Traewelling/traewelling/issues/1772',
'token' => $token->accessToken,
'expires_at' => $token->token->expires_at->toIso8601String(),
])
->header('Authorization', $token->accessToken);
}
return $this->sendError('Non-matching credentials', 401);
}

/**
* @OA\Post(
* path="/auth/logout",
Expand Down Expand Up @@ -134,7 +111,8 @@ public function refresh(Request $request): JsonResponse {
$oldToken->revoke();
return $this->sendResponse([
'token' => $newToken->accessToken,
'expires_at' => $newToken->token->expires_at->toIso8601String()]
)->header('Authorization', $newToken->accessToken);
'expires_at' => $newToken->token->expires_at->toIso8601String()
])
->header('Authorization', $newToken->accessToken);
}
}
1 change: 0 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

Route::group(['prefix' => 'v1', 'middleware' => ['return-json']], static function() {
Route::group(['prefix' => 'auth'], function() {
Route::post('login', [v1Auth::class, 'login']);
Route::group(['middleware' => 'auth:api'], static function() {
Route::post('refresh', [v1Auth::class, 'refresh']);
Route::post('logout', [v1Auth::class, 'logout']);
Expand Down

0 comments on commit e827380

Please sign in to comment.