PHP code example of maslennikov-yv / jwt-guard

1. Go to this page and download the library: Download maslennikov-yv/jwt-guard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maslennikov-yv / jwt-guard example snippets


Auth::extend('jwt', function ($app, $name, array $config) use ($public_key) {
    return new JwtGuard($provider, $request, function ($token) use ($public_key) {
        try {
            $content = JWT::decode($token, new Key($public_key, 'RS256'));
            return property_exists($content, 'sub') ? $content->sub : null;
        } catch (Exception $e) {
            Log::debug($e->getMessage());
        }
        return null;
    });
});

composer