Exemplo n.º 1
0
/**
 * @link http://bshaffer.github.io/oauth2-server-php-docs/grant-types/jwt-bearer/
 */
function generateJwtAssertion($privateKey, $iss, $sub, $aud, $exp = null, $nbf = null, $jti = null)
{
    if (!$exp) {
        $exp = time() + 1000;
    }
    $params = array('iss' => $iss, 'sub' => $sub, 'aud' => $aud, 'exp' => $exp, 'iat' => time());
    if ($nbf) {
        $params['nbf'] = $nbf;
    }
    if ($jti) {
        $params['jti'] = $jti;
    }
    $jwtUtil = new JwtUtil();
    return $jwtUtil->encode($params, $privateKey, 'RS256');
}