public static function getNonce(string $action, Session $session, array $context = [], int $timestamp = null)
    {
        // When nonce are not allowed to be stored, the nonce is not actually 
        // used only once since it needs to be reproducable to be verifiable.
        // Therefore, it sent timestamped to the client.
        $timestamp = $timestamp ?? time();
        $hashable = $action . $timestamp . $session->getSessionSalt();
        foreach ($context as $key => $value)
        {
            if ($value === null)
                $value = "NULL";
            if (!is_scalar($value))
                throw new InvalidArgumentException("Context variables must be scalar");
            $hashable .= '&' . $key . '=' . $value;
        }

        $nonce = sha1($hashable) . '$' . $timestamp;
        return $nonce;
    }
public static function getNonce(string $action, Session $session, array $context = [], int $timestamp = null)
    {
        // When nonce are not allowed to be stored, the nonce is not actually 
        // used only once since it needs to be reproducable to be verifiable.
        // Therefore, it sent timestamped to the client.
        $timestamp = $timestamp ?? time();
        $hashable = $action . $timestamp . $session->getSessionSalt();
        foreach ($context as $key => $value)
        {
            if ($value === null)
                $value = "NULL";
            if (!is_scalar($value))
                throw new InvalidArgumentException("Context variables must be scalar");
            $hashable .= '&' . $key . '=' . $value;
        }

        $nonce = sha1($hashable) . '$' . $timestamp;
        return $nonce;
    }
public static function getNonce ( string $ action , Session $ session , array $ context = [ ] , int $ timestamp = null ) { // When nonce are not allowed to be stored, the nonce is not actually  // used only once since it needs to be reproducable to be verifiable. // Therefore, it sent timestamped to the client. $ timestamp = $ timestamp ?? time ( ) ; $ hashable = $ action . $ timestamp . $ session -> getSessionSalt ( ) ; foreach ( $ context as $ key => $ value ) { if ( $ value === null ) $ value = "NULL" ; if ( ! is_scalar ( $ value ) ) throw new InvalidArgumentException ( "Context variables must be scalar" ) ; $ hashable .= '&' . $ key . '=' . $ value ; } $ nonce = sha1 ( $ hashable ) . '$' . $ timestamp ; return $ nonce ; }
Get a nonce for the specified action optionally including context
@param string $action The action to tie the nonce to
@param Session $session The session to get the session salt from
@param array $context The context required for the nonce to be validated
@return string The nonce that should be submitted as parameter nonce
Get a nonce for the specified action optionally including context