Frontendde AngularJS ve Satellizer denen login eklentisini kullanıyorum. /auth/login yoluna POST methoduyla login bilgilerini yolluyorum. Sunucu kısmında klein.php router kullandım. Takıldığım kısım ise php kısmında doğrulama işlemini nasıl yapacağım ve kullanıcı login veya register olduktan sonra response olarak frontende bir JWT(Json Web Token) yollamam gerekiyor. Popüler olan bir php-jwt eklentisi buldum fakat nasıl kullanılacağını bilmiyorum.

PHP-JWT eklentisi:https://github.com/lcobucci/jwt

Klein.php router: https://github.com/klein/klein.php

Laravel ile yazılmış örnek: https://github.com/sahat/satellizer/...Controller.php

<?php
require_once __DIR__ . '/vendor/autoload.php';

$klein = new \Klein\Klein();

use Lcobucci\JWT\Builder;

$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
                        ->setAudience('http://example.org') // Configures the audience (aud claim)
                        ->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
                        ->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
                        ->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim)
                        ->setExpiration(time() + 3600) // Configures the expiration time of the token (nbf claim)
                        ->set('uid', 1) // Configures a new claim, called "uid"
                        ->getToken(); // Retrieves the generated token


$klein->respond('POST', '/auth/login', function($request, $response){
    $req = $request->body();
    $data = json_decode($req);
    $email = $data->email;
    $gecPassword = $data->password;

});
$klein->dispatch();