This repository is archived. Use the OIDC support built into the
reflex-enterprisepackage instead.Notably, this package stores tokens in
LocalStorage, which is readable by any script running on the page (e.g. via XSS). Thereflex-enterpriseOIDC state stores tokens in HttpOnly,Secure,SameSite=Strictcookies, and additionally provides refresh tokens with cross-tab sync, nonce /at_hashvalidation, and granted-scope tracking. Functionally, anything this package does is also covered there.Subclass
OIDCAuthStatewith__provider__ = "okta"— the sameOKTA_CLIENT_ID,OKTA_CLIENT_SECRET, andOKTA_ISSUER_URIenv vars are picked up automatically (config lookup is{PROVIDER}_*):import reflex as rx from reflex_enterprise.auth.oidc.state import OIDCAuthState class OktaAuthState(OIDCAuthState, rx.State): __provider__ = "okta"Render the login button — endpoints are registered automatically on first use, so no explicit
register_auth_endpoints(app)call is needed:OktaAuthState.get_login_button("Log In with Okta")Logout (
redirect_to_logout) anduserinfokeep the same names and shape.
This package requires the reflex_enterprise package to be installed.
pip install reflex-okta-authCreate a new Application and set up a .env file with the following variables:
OKTA_CLIENT_ID=your_client_id
OKTA_CLIENT_SECRET=your_client_secret
OKTA_ISSUER_URI=your oauth issuer uriReflex will need to access these variables to authenticate users.
from reflex_enterprise import App
from reflex_okta_auth import register_auth_endpoints
...
app = App()
register_auth_endpoints(app)import reflex as rx
from reflex_okta_auth import OktaAuthState
@rx.page()
def index():
return rx.container(
rx.vstack(
rx.heading("Okta Auth Demo"),
rx.cond(
rx.State.is_hydrated,
rx.cond(
OktaAuthState.userinfo,
rx.vstack(
rx.text(f"Welcome, {OktaAuthState.userinfo["name"]}!"),
rx.text(OktaAuthState.userinfo.to_string()),
rx.button("Logout", on_click=OktaAuthState.redirect_to_logout),
),
rx.button("Log In with Okta", on_click=OktaAuthState.redirect_to_login),
),
rx.spinner(),
),
),
)Before performing privileged backend operations, it is important to validate the
tokens to ensure they have not been tampered with. Use
OktaAuthState._validate_tokens() helper method to validate the tokens.