Documentation

Cosession extends AutoService
in package
implements EventSubscriberInterface

The co-session provides a long (real) session built on top of short (fake) sessions.

Within an iframe context, cookies are unreliable. The CMS creates cookies and sessions, but they only work for 1 page-load. On the next page-load, you're in a new session. These short sessions are kind of pointless - but they're baked into each CMS (cumbersome to fine-tune). To achieve session-like behavior, we need to propagate request-parameters instead.

For the "iframe co-session", we sync the short-lived CMS sessions with a long-lived co-session.

  • The co-session is stored separately (via Civi::cache('session'))
  • The co-session is activated by a request-parameter (?_cosession={JWT}) instead of a cookie.
  • The request-parameter is outputted at key moments (e.g. hook_buildForm) so that it propagates to subsequent requests.
  • As the request begins (as the CMS session starts), we import data from the co-session.
  • As the request finishes (as the CMS session ends), we export data back to the co-session.
Tags
service

iframe.cosession

Table of Contents

Interfaces

EventSubscriberInterface

Properties

$jwt  : CryptoJwt
$sessionId  : string|null
$ttl  : mixed

Methods

export()  : mixed
Export data from the short-lived CMS session. Save it to the co-session.
findCreateSessionId()  : string|null
getSubscribedEvents()  : array<string|int, mixed>
import()  : mixed
Get the long-lived co-session. Import data into the short-lived CMS session.
isEmbeddable()  : bool
Determine whether the request is allowed within an iframe iframe.
onBuildForm()  : mixed
onInvoke()  : mixed
onRedirect()  : mixed
pickTheme()  : void
createSessionId()  : string
createToken()  : string
parseToken()  : string
rotateSessionId()  : void

Properties

$sessionId

protected string|null $sessionId = NULL

Methods

export()

Export data from the short-lived CMS session. Save it to the co-session.

public export() : mixed

findCreateSessionId()

public findCreateSessionId() : string|null
Return values
string|null

getSubscribedEvents()

public static getSubscribedEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>

import()

Get the long-lived co-session. Import data into the short-lived CMS session.

public import() : mixed

isEmbeddable()

Determine whether the request is allowed within an iframe iframe.

public isEmbeddable(string $path) : bool
Parameters
$path : string

Ex: 'civicrm/foo/bar'

Return values
bool

TRUE if this path is embeddable

onInvoke()

public onInvoke(array<string|int, mixed> $path) : mixed
Parameters
$path : array<string|int, mixed>

onRedirect()

public onRedirect(UriInterface &$redirectUrl, mixed &$context) : mixed
Parameters
$redirectUrl : UriInterface
$context : mixed

createSessionId()

protected createSessionId() : string
Return values
string

createToken()

protected createToken(mixed $sessionId) : string
Parameters
$sessionId : mixed
Return values
string

parseToken()

protected parseToken(string $token) : string
Parameters
$token : string
Return values
string

rotateSessionId()

protected rotateSessionId() : void

        
On this page

Search results