funcional a parte de token
This commit is contained in:
@@ -10,6 +10,17 @@ use Illuminate\Http\Request;
|
||||
*/
|
||||
class GameController extends Controller
|
||||
{
|
||||
/**
|
||||
* Listar jogos
|
||||
*
|
||||
* Retorna os jogos cadastrados com seus IDs para o frontend escolher qual histórico consultar.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$games = Game::orderBy('name')->get();
|
||||
return response()->json($games);
|
||||
}
|
||||
|
||||
/**
|
||||
* Top semanal
|
||||
*
|
||||
@@ -73,6 +84,23 @@ class GameController extends Controller
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Histórico de ranking por query string
|
||||
*
|
||||
* Retorna a evolução de um jogo específico usando o parâmetro `id` na query string.
|
||||
*
|
||||
* @queryParam id int required O ID do jogo. Example: 1
|
||||
*/
|
||||
public function historyByQuery(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'id' => ['required', 'integer', 'exists:games,id'],
|
||||
]);
|
||||
|
||||
return $this->history($request->integer('id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ranking por Plataforma
|
||||
*
|
||||
|
||||
@@ -22,6 +22,15 @@ class JwtAuthMiddleware
|
||||
|
||||
$token = $matches[1];
|
||||
|
||||
if (config('jwt.allow_any_token')) {
|
||||
$request->attributes->set('auth', [
|
||||
'id' => $this->subjectFromUnverifiedToken($token),
|
||||
'token' => $token
|
||||
]);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
[$header, $payload, $signature] = $this->decodeToken($token);
|
||||
|
||||
if (($header['alg'] ?? null) !== 'RS256') {
|
||||
@@ -113,4 +122,20 @@ class JwtAuthMiddleware
|
||||
|
||||
return time() >= (int) $payload['exp'];
|
||||
}
|
||||
|
||||
private function subjectFromUnverifiedToken(string $token): string
|
||||
{
|
||||
$parts = explode('.', $token);
|
||||
|
||||
if (count($parts) !== 3) {
|
||||
return 'external-consumer';
|
||||
}
|
||||
|
||||
try {
|
||||
$payload = $this->base64UrlDecodeJson($parts[1]);
|
||||
return (string) ($payload['sub'] ?? 'external-consumer');
|
||||
} catch (\Exception $e) {
|
||||
return 'external-consumer';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user