SimpleSAML_Auth_State::saveState PHP Method

saveState() public static method

This function saves the state, and returns an id which can be used to retrieve it later. It will also update the $state array with the identifier.
public static saveState ( &$state, string $stage, boolean $rawId = false ) : string
$stage string The current stage in the login process.
$rawId boolean Return a raw ID, without a restart URL.
return string Identifier which can be used to retrieve the state later.
    public static function saveState(&$state, $stage, $rawId = false)
    {
        assert('is_array($state)');
        assert('is_string($stage)');
        assert('is_bool($rawId)');
        $return = self::getStateId($state, $rawId);
        $id = $state[self::ID];
        // Save stage
        $state[self::STAGE] = $stage;
        // Save state
        $serializedState = serialize($state);
        $session = SimpleSAML_Session::getSessionFromRequest();
        $session->setData('SimpleSAML_Auth_State', $id, $serializedState, self::getStateTimeout());
        SimpleSAML\Logger::debug('Saved state: ' . var_export($return, true));
        return $return;
    }

Usage Example

 /**
  * Log in using an external authentication helper.
  *
  * @param array &$state  Information about the current authentication.
  */
 public function authenticate(&$state)
 {
     $state['openidconnect:AuthID'] = $this->authId;
     $stateId = SimpleSAML_Auth_State::saveState($state, 'openidconnect:Connect', TRUE);
     $info = $this->getConfig($stateId);
     \SimpleSAML\Utils\HTTP::redirectTrustedURL($info["client_info"]["authorization_endpoint"], array("client_id" => $info["client_info"]["client_id"], "redirect_uri" => $info["client_info"]["redirect_uri"], "response_type" => "code", "scope" => $this->scope, "state" => $stateId));
 }
All Usage Examples Of SimpleSAML_Auth_State::saveState