MediaWiki master
MediaWiki\Session\JwtSessionCookieHelper Class Reference

Public Member Functions

 __construct (private readonly UrlUtils $urlUtils, private readonly Config $config, protected JwtCodec $jwtCodec, private readonly SessionManager $sessionManager, private readonly string $sessionProviderType, private readonly CentralIdLookup $centralIdLookup, private readonly UserFactory $userFactory)
 
 getJwtClaimOverrides (int $expirationDuration)
 Helper method to make it easy for subclasses to alter claims.
 
 getJwtCookieSessionExpiration ()
 Expiration duration for the JWT session cookie.
 
 getJwtIssuer ()
 
 setJwtCookie (User $user, WebRequest $request, array $jwtCookieOptions, array $jwtClaimOverrides)
 Emit a JWT cookie containing the user ID, token and other information.
 
 useJwtCookie ()
 Tells whether the provider should emit session data as a JWT cookie, alongside of (in the future, possibly instead of) the normal session cookies.
 
 verifyJwtCookie (WebRequest $request, SessionInfo &$sessionInfo, array $jwtCookieOptions, array $jwtClaimOverrides)
 Ensure that the JWT cookie (if it exists) matches the SessionInfo.
 

Public Attributes

const JWT_COOKIE_NAME = 'sessionJwt'
 Name of the JWT cookie, when enabled.
 

Protected Member Functions

 getUserFromJwtData (array $jwtData)
 

Protected Attributes

string $jti = null
 JWT 'jti' field.
 

Detailed Description

Definition at line 24 of file JwtSessionCookieHelper.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Session\JwtSessionCookieHelper::__construct ( private readonly UrlUtils $urlUtils,
private readonly Config $config,
protected JwtCodec $jwtCodec,
private readonly SessionManager $sessionManager,
private readonly string $sessionProviderType,
private readonly CentralIdLookup $centralIdLookup,
private readonly UserFactory $userFactory )
Parameters
UrlUtils$urlUtils
Config$config
JwtCodec$jwtCodec
SessionManager$sessionManager
string$sessionProviderType
CentralIdLookup$centralIdLookup
UserFactory$userFactory

Definition at line 48 of file JwtSessionCookieHelper.php.

Member Function Documentation

◆ getJwtClaimOverrides()

MediaWiki\Session\JwtSessionCookieHelper::getJwtClaimOverrides ( int $expirationDuration)

Helper method to make it easy for subclasses to alter claims.

Parameters
int$expirationDurationSession lifetime in seconds.
Returns
array

Definition at line 281 of file JwtSessionCookieHelper.php.

◆ getJwtCookieSessionExpiration()

MediaWiki\Session\JwtSessionCookieHelper::getJwtCookieSessionExpiration ( )

Expiration duration for the JWT session cookie.

Returns
mixed

Definition at line 266 of file JwtSessionCookieHelper.php.

◆ getJwtIssuer()

MediaWiki\Session\JwtSessionCookieHelper::getJwtIssuer ( )

Definition at line 270 of file JwtSessionCookieHelper.php.

◆ getUserFromJwtData()

MediaWiki\Session\JwtSessionCookieHelper::getUserFromJwtData ( array $jwtData)
protected
Exceptions
JwtException

Definition at line 97 of file JwtSessionCookieHelper.php.

◆ setJwtCookie()

MediaWiki\Session\JwtSessionCookieHelper::setJwtCookie ( User $user,
WebRequest $request,
array $jwtCookieOptions,
array $jwtClaimOverrides )

Emit a JWT cookie containing the user ID, token and other information.

Definition at line 70 of file JwtSessionCookieHelper.php.

◆ useJwtCookie()

MediaWiki\Session\JwtSessionCookieHelper::useJwtCookie ( )

Tells whether the provider should emit session data as a JWT cookie, alongside of (in the future, possibly instead of) the normal session cookies.

Definition at line 63 of file JwtSessionCookieHelper.php.

◆ verifyJwtCookie()

MediaWiki\Session\JwtSessionCookieHelper::verifyJwtCookie ( WebRequest $request,
SessionInfo & $sessionInfo,
array $jwtCookieOptions,
array $jwtClaimOverrides )

Ensure that the JWT cookie (if it exists) matches the SessionInfo.

A missing JWT cookie is treated as a success.

If the SessionInfo has a UserInfo, verifies that the JWT cookie contains the same user. If the SessionInfo does not have a UserInfo, an unverified UserInfo will be added to it based on the JWT data (so the verification will happen in SessionManager::loadSessionInfoFromStore()).

Marks the session to be refreshed if the JWT cookie is missing (but based on the SessionInfo should be there) or is near expiry.

Exceptions
JwtExceptionon error

Definition at line 134 of file JwtSessionCookieHelper.php.

References MediaWiki\Session\SessionInfo\getPriority(), MediaWiki\Session\SessionInfo\getProvider(), MediaWiki\Session\SessionInfo\getUserInfo(), and MediaWiki\Session\SessionInfo\wasPersisted().

Member Data Documentation

◆ $jti

string MediaWiki\Session\JwtSessionCookieHelper::$jti = null
protected

JWT 'jti' field.

FIXME This is an ugly hack to make the cookie set in setJwtCookie() deterministic within a given request. We don't have a mechanism to avoid writing cookies several times per request, and rely on WebResponse deduplicating cookies as long as the values are the same.

Definition at line 37 of file JwtSessionCookieHelper.php.

◆ JWT_COOKIE_NAME

const MediaWiki\Session\JwtSessionCookieHelper::JWT_COOKIE_NAME = 'sessionJwt'

Name of the JWT cookie, when enabled.

Ignores $wgCookiePrefix.

Definition at line 29 of file JwtSessionCookieHelper.php.


The documentation for this class was generated from the following file: