Skip to content

Commit

Permalink
feat:add configurable state
Browse files Browse the repository at this point in the history
  • Loading branch information
shtayerc committed Oct 4, 2022
1 parent 6aae75b commit e084a1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]
* Added support for custom state. #336

## [0.9.10]

## Fixed
Expand Down
26 changes: 25 additions & 1 deletion src/OpenIDConnectClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ class OpenIDConnectClient
*/
private $token_endpoint_auth_methods_supported = ['client_secret_basic'];

/**
* @var string state to be used instead of random string
*/
private $customState;

/**
* @param $provider_url string optional
*
Expand Down Expand Up @@ -792,7 +797,7 @@ private function requestAuthorization() {
$nonce = $this->setNonce($this->generateRandString());

// State essentially acts as a session key for OIDC
$state = $this->setState($this->generateRandString());
$state = $this->setState($this->getCustomState() ?: $this->generateRandString());

$auth_params = array_merge($this->authParams, [
'response_type' => $response_type,
Expand Down Expand Up @@ -1946,6 +1951,25 @@ protected function unsetState() {
$this->unsetSessionKey('openid_connect_state');
}

/**
* Set customState
*
* @param string $state
* @return void
*/
public function setCustomState($state) {
$this->customState = $state;
}

/**
* Get customState
*
* @return string
*/
public function getCustomState() {
return $this->customState;
}

/**
* Stores $codeVerifier
*
Expand Down

0 comments on commit e084a1a

Please sign in to comment.