You are here

public static function JWT::encode in Auth0 Single Sign On 8.2

Converts and signs a PHP object or array into a JWT string.

@uses jsonEncode @uses urlsafeB64Encode

Parameters

object|array $payload PHP object or array:

string $key The secret key.: If the algorithm used is asymmetric, this is the private key

string $alg The signing algorithm.: Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'

mixed $keyId:

array $head An array with header elements to attach:

Return value

string A signed JWT

4 calls to JWT::encode()
Auth0Test::testThatExchangeSkipsUserinfo in vendor/auth0/auth0-php/tests/Auth0Test.php
Test that the skip_userinfo config option uses the ID token instead of calling /userinfo.
Auth0Test::testThatExchangeSucceedsWithIdToken in vendor/auth0/auth0-php/tests/Auth0Test.php
Test that the exchanges succeeds when there is both and access token and an ID token present.
Auth0Test::testThatRenewTokensSucceeds in vendor/auth0/auth0-php/tests/Auth0Test.php
Test that renewTokens succeeds with non-empty access_token and refresh_token stored.
TokenGenerator::generate in vendor/auth0/auth0-php/src/API/Helpers/TokenGenerator.php
Create the ID token.

File

vendor/firebase/php-jwt/src/JWT.php, line 166

Class

JWT
JSON Web Token implementation, based on this spec: https://tools.ietf.org/html/rfc7519

Namespace

Firebase\JWT

Code

public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null) {
  $header = array(
    'typ' => 'JWT',
    'alg' => $alg,
  );
  if ($keyId !== null) {
    $header['kid'] = $keyId;
  }
  if (isset($head) && \is_array($head)) {
    $header = \array_merge($head, $header);
  }
  $segments = array();
  $segments[] = static::urlsafeB64Encode(static::jsonEncode($header));
  $segments[] = static::urlsafeB64Encode(static::jsonEncode($payload));
  $signing_input = \implode('.', $segments);
  $signature = static::sign($signing_input, $key, $alg);
  $segments[] = static::urlsafeB64Encode($signature);
  return \implode('.', $segments);
}