How to name the firebase / php-jwt class in Laravel 5

Currently I want to implement firebase / php-jwt in laravel 5

I ran a command composer require firebase/php-jwtunder my laravel 5 project and I got

"require": {
    ...
    "firebase/php-jwt": "^3.0"
},

in package.json

from config / app.php I need to add this library, but I don't know how to do it.


Decision:

use tymondesigns / jwt-auth instead ,
and follow the JSON Web Token Tutorial: an example in Laravel and AngularJS

Even if your interface does not use angular, it does not matter

+5
source share
2 answers

After installing it through the composer,

Add these two lines to your app.php

'J42\LaravelFirebase\LaravelFirebaseServiceProvider',

and

'Firebase'        => 'J42\LaravelFirebase\LaravelFirebaseFacade'

Also do not forget to add credentials to your config/database.php

Tip 1:

Firebase::get('/my/path');

,

2: - , .

+1

5 : ,

    "require": {
        ...
        "firebase/php-jwt": "^5.0",
    },

:

use Firebase\JWT\JWT;

...
protected function generateJwt(){
        if (config('jwt.secret')) {
            $now_seconds = time();
            $payload = array(
                    "iss" => ...,
                    "sub" => ...,
                    "aud" => ...,
                    "iat" => $now_seconds,
                    "exp" => $now_seconds + 60*60,  // Maximum expiration time is one hour
            );

            $this->jwt = JWT::encode($payload, config('jwt.secret'), "HS256");
        }

        Log::error("Missing JWT_SECRET in .env");
    }
0

Source: https://habr.com/ru/post/1620035/


All Articles