Laravel JWT autoryzacja

0

Witam,

chcę wdrożyć autoryzację JWT w projekcie, mam kontroler logowania


/**
     * Get a JWT token via given credentials.
     *
     * @param  \Illuminate\Http\Request  $request
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function login(Request $request)
    {
        $credentials = $request->only('email', 'password');
        if ($token = $this->guard()->attempt($credentials)) {
            return $this->respondWithToken($token);
        }
        return response()->json(['error' => 'Unauthorized'], 401);
    }
    /**
     * Get the authenticated User
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function me()
    {
        return response()->json($this->guard()->user());
    }
    /**
     * Log the user out (Invalidate the token)
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function logout()
    {
        $this->guard()->logout();
        return response()->json(['message' => 'Successfully logged out']);
    }
    /**
     * Refresh a token.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function refresh()
    {
        return $this->respondWithToken($this->guard()->refresh());
    }
    /**
     * Get the token array structure.
     *
     * @param  string $token
     *
     * @return \Illuminate\Http\JsonResponse
     */
    protected function respondWithToken($token)
    {
        return response()->json([
            'token' => $token,
            'token_type' => 'bearer',
            'expires_in' => $this->guard('api')->factory()->getTTL() * 60
        ]);
    }
    /**
     * Get the guard to be used during authentication.
     *
     * @return \Illuminate\Contracts\Auth\Guard
     */
    public function guard()
    {
        return Auth::guard('api');
    }

wygenerowałem klucz publiczny i prywatny, w .env dodałem


JWT_PUBLIC_KEY=jwt/public.pem
JWT_PRIVATE_KEY=jwt/public.pem
JWT_PASSPHRASE=password
JWT_ALGO=RS256


i otrzymuję błąd


Could not create token: It was not possible to parse your key, reason: error:0906D06C:PEM routines:PEM_read_bio:no start line


0

https://github.com/yagop/node-telegram-bot-api/issues/63#issuecomment-207149749
Może to pomoże?

PS. Proponuję poszukać błędu w Google, dużo osób miało taki problem.

0

hmm? nie wiem z jakiej wersji jwt korzystasz ale wszędzie gdzie ja używam ustawiało się tylko JWT_SECRED generowany poleceniem artisana, nic nie było nigdy czytane z plików kluczy

0

wcześniej zrobiłem dokładnie tak jak mówisz jednak potem się dowiedziałem że w takim wydaniu nie ma sprawdzania podpisu tokenu i w jednym z tutoriali było właśnie takie rozwiązanie

1 użytkowników online, w tym zalogowanych: 0, gości: 1