Skip to content

State

You will probably never need to use this. It is used internally by the clients to create a JWT from a state or to validate a given JWT. You should use JWTs directly instead.

eternaltwin.states.State

State(a: str, as_: str, iat: int, rfp: int, exp: int, nonce: str, key: KeyABC)

Represents an authorization state.

Parameters:

Name Type Description Default
a str

Action.

required
as_ str

Authorization server URL.

required
iat int

Issued at timestamp.

required
rfp int

Request forgery protection as a timestamp.

required
exp int

Expiration timestamp.

required
nonce str

Nonce value.

required
key KeyABC

Key used to encode the state.

required

jwt property

jwt: str

Return the state as a JWT.

new classmethod

new(url: str, key: KeyABC, expiration: int = 600, nonce: str = None) -> Self

Create a new state using given parameters.

Parameters:

Name Type Description Default
url str

URL of the authorization server.

required
key KeyABC

Key used to encode the state.

required
expiration int

Expiration time in seconds.

600
nonce str

An optional nonce value used to guarantee the state to be unique. If not provided, a random one will be generated.

None

from_jwt classmethod

from_jwt(jwt: str, url: str, key: KeyABC) -> Self

Create a state from a JWT.

Parameters:

Name Type Description Default
jwt str

JWT string representing the state.

required
url str

URL of the authorization server.

required
key KeyABC

Key used to decode the state.

required

Raises:

Type Description
InvalidStateError

If action or authorization server does not match, or the JWT is expired.

has_expired

has_expired() -> bool

Check if the state has expired.