namshi / jose

JSON Object Signing and Encryption library for PHP.
MIT License
1.8k stars 133 forks source link

SimpleJWS App #104

Open PB314 opened 8 years ago

PB314 commented 8 years ago

Can someone please include a an implementation example of the "SimpleJWS" script that is not a unit test. All the unit tests work flawlessly, and arguably very often prove nothing. A simple test like the one below is far more useful however this simple test is difficult to configure if you are new to composer and namespaces. That is the code below will not work without refinement and ensuring that the autoloader is invoked.. It would be very helpful if someone could include a working version. `

<?php
use Namshi\JOSE\SimpleJWS;
if ($username == 'correctUsername' && $pass == 'ok') {
    $user = Db::loadUserByUsername($username);
    $jws  = new SimpleJWS(array(
        'alg' => 'RS256'
    ));
    $jws->setPayload(array(
        'uid' => $user->getid(),
    ));
    $privateKey = openssl_pkey_get_private("file://path/to/private.key", self::SSL_KEY_PASSPHRASE);
    $jws->sign($privateKey);
    setcookie('identity', $jws->getTokenString());
}