Skip to content

Instantly share code, notes, and snippets.

@mspivak
Created September 21, 2016 20:15
Show Gist options
  • Save mspivak/3979ac261f73b886e94ead6844380e43 to your computer and use it in GitHub Desktop.
Save mspivak/3979ac261f73b886e94ead6844380e43 to your computer and use it in GitHub Desktop.
Alternative to layerhq/layer-identity-token-php that works on Laravel 4.2
<?php
use Namshi\JOSE\JWS;
class AuthController extends Controller {
function layer_identity_token() {
if (Auth::user()->id !== Input::get('user_id')) {
App::abort(500);
}
$jws = new JWS('JWT');
$jws->setHeader([
'typ' => 'JWT',
'alg' => 'RS256',
'cty' => 'layer-eit;v=1',
'kid' => Config::get('services.layer.private_key_id')
]);
$jws->setPayload([
'iss' => Config::get('services.layer.provider_id'),
'prn' => (string) Auth::user()->id,
'iat' => (int) Carbon::now()->format('U'),
'exp' => (int) Carbon::now()->addMinutes(5)->format('U'),
'nce' => Input::get('nonce'),
'display_name' => Auth::user()->account->name
]);
$privateKey = openssl_pkey_get_private(Config::get('services.layer.private_key'));
$jws->sign($privateKey);
return [
'identity_token' => $jws->getTokenString()
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment