user(); $tokens = $user->tokens()->get(); return new ApiTokenCollection($tokens); } /** * Create a new api token for the currently authenticated user * * The response will contain the access token that can be used to send authenticated API requests. * Please note that the access token is only shown in this response and cannot be retrieved later. * * @throws AuthorizationException */ public function store(ApiTokenStoreRequest $request): ApiTokenWithAccessTokenResource { $user = $this->user(); $token = $user->createToken($request->getName(), ['*']); /** @var Token $tokenModel */ $tokenModel = $token->token; return new ApiTokenWithAccessTokenResource($tokenModel, $token->accessToken); } /** * Revoke an api token * * @throws AuthorizationException */ public function revoke(string $apiTokenId): JsonResponse { $user = $this->user(); $apiToken = $user->tokens()->where('id', $apiTokenId)->firstOrFail(); $apiToken->revoke(); return response()->json(null, 204); } /** * Delete an api token * * @throws AuthorizationException */ public function destroy(string $apiTokenId): JsonResponse { $user = $this->user(); $apiToken = $user->tokens()->where('id', $apiTokenId)->firstOrFail(); $apiToken->delete(); return response()->json(null, 204); } }