Skip to content

Support entitlements in the Session #336

@adam-h

Description

@adam-h

With WorkOS now integrating with Stripe to include entitlements in the session [1], it'd be great to have this built-in to the ruby library.

For now we're working around it by re-decoding the access token in our application to access the entitlements, something like:

# Assuming `session_data` is already defined with the sealed session data
session_instance = WorkOS::UserManagement.load_sealed_session \
  client_id: credentials.client_id,
  session_data:,
  cookie_password: credentials.cookie_password

# Reach into `WorkOS::Session` and re-decode the JWT to get the underlying access token
unsealed_session = WorkOS::Session.unseal_data(session_instance.session_data, session_instance.cookie_password)
token = JWT.decode(unsealed_session[:access_token], nil, true, algorithms: session_instance.jwks_algorithms, jwks: session_instance.jwks).first

# We now have the underlying token, and through it the entitlements
puts token["entitlements"]

This works for now, so it's not super urgent for us, it's just not very clean code :)

1: https://workos.com/docs/user-management/entitlements

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions