Download the PHP package ua/okta-oidc without Composer

On this page you can find all versions of the php package ua/okta-oidc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package okta-oidc

UA Laravel Okta OIDC

A reusable Okta OIDC authentication package for Laravel applications. Provides login, callback, logout, and session-expiry flows out of the box — without forcing any particular local user model on your app.

Requirements

Quick Start

1. Install the package

2. Publish the config

3. Add your Okta credentials to .env

4. Protect your routes

That's it. Unauthenticated users are redirected to Okta, and after login they land back on the page they originally requested.

How It Works

When a user hits a protected route:

  1. The okta-oidc.auth middleware checks for a valid OIDC session
  2. If missing/expired, the user is redirected to Okta to sign in
  3. After Okta authentication, the callback route:
    • Resolves a principal (username, email, etc.) via a PrincipalResolver
    • Stores the principal, ID token, and expiration in the session
    • Runs a UserBootstrapper to perform any additional setup (session claims, database user, etc.)
    • Redirects back to the originally requested page

If the state parameter Okta returns does not match the one stored in the session, the callback cannot be trusted and the user is redirected to the expired page with the okta_oidc_expired flash flag — the same state the okta-oidc.auth middleware uses for a dead session. This usually means a stale login tab, a back-button revisit, or a session that did not survive the round trip.

The expired page is deliberately a terminal destination with a sign-in link, rather than an automatic bounce back to okta-oidc.login. If the underlying cause is that sessions are not persisting at all, an automatic retry would loop between the callback and Okta indefinitely, since Okta still holds an authenticated session and redirects back without any user interaction.

Routes

The package registers these routes under the auth/oidc prefix (configurable):

Method URI Name Purpose
GET /auth/oidc/login okta-oidc.login Redirect to Okta
GET /auth/oidc/callback okta-oidc.callback Handle Okta response
GET\|POST /auth/oidc/logout okta-oidc.logout Destroy session + Okta logout
GET /auth/oidc/expired okta-oidc.expired Session expired page
GET /auth/oidc/logged-out okta-oidc.logged-out Logout confirmation page

Principal Resolvers

A PrincipalResolver extracts a user identifier from the OIDC user object returned by Okta. This identifier is stored in the session as the "principal" — typically a username or email.

Built-in Resolvers

Resolver Config Value Behavior Example Output
UsernamePrincipalResolver Default preferred_username local part, lowercased jdoe
UserPrincipalNamePrincipalResolver Opt-in Full preferred_username, lowercased [email protected]
EmailPrincipalResolver Opt-in Full email, lowercased [email protected]
OktaIdPrincipalResolver Opt-in Okta user ID 00u21yawsni0DL5V51d8

To switch resolvers, update config/okta-oidc.php:

Creating Your Own

Implement Ua\LaravelOktaOidc\Contracts\PrincipalResolver:

Then reference it in config:

User Bootstrappers

A UserBootstrapper runs after authentication to perform app-specific setup — storing claims in the session, creating database records, calling Auth::login(), etc. The bootstrapper is called after the core session keys (principal, ID token, expiration) are already stored.

Built-in Bootstrappers

NullUserBootstrapper

Does nothing. Use this if you only need the core session keys and handle everything else yourself.

SessionUserBootstrapper (Default)

Stores configurable OIDC claims into the session. Controlled by the session_claims config:

Accessor types:

Accessor Behavior Example
'getName' Calls the method on the Socialite user object getName(), getEmail()
'@raw' Stores the entire raw OIDC claims array All JWT claims
'preferred_username' Looks up a key in the raw claims via data_get() Supports dot notation like 'address.city'

After login, access the claims from the session:

You can add your own claims to the mapping:

EloquentUserBootstrapper

Extends SessionUserBootstrapper — stores session claims and creates/updates a local Eloquent User record, then calls Auth::login(). This gives you full Auth::user() support backed by Laravel's default users table.

On each login it:

  1. Stores OIDC claims in the session (inherited from SessionUserBootstrapper)
  2. Finds or creates a User by email (firstOrCreate)
  3. Syncs the user's name from Okta
  4. Sets a random hashed password on first creation (users authenticate via OIDC, not passwords)
  5. Calls Auth::login($user)

The User model class is configurable:

Or via environment variable:

Guard Hydration (hydrate_guard)

By default, the session-only bootstrappers never touch Laravel's auth guard, so Auth::user() returns null even though the OIDC session is valid. That means guard-based tooling — monitoring like Laravel Nightwatch, Auth::id() in logs, etc. — sees every request as a guest.

If your app has no local users table (or you just don't want database-backed users), enable guard hydration:

When enabled, the okta-oidc.auth middleware populates the default guard on every request with a valid OIDC session, using a GenericUser built from the session:

This is request-scoped only: Auth::setUser() does not log the user in or store anything in the session, and no user provider or database lookup is involved. If a real user is already authenticated (e.g. via EloquentUserBootstrapper), hydration is skipped and the real user wins.

With SESSION_DRIVER=database, Laravel copies Auth::id() into sessions.user_id on every session write. That column is a numeric foreignId in Laravel's default migration, so the package registers its own database session handler that stores null there for the hydrated user. The principal still reaches Auth::id(), logs, and Nightwatch; real authenticated users are stored exactly as before. No migration change is needed.

Note: With hydration enabled, anything guard-based — the auth middleware, policies, Auth::check() — will see the generic user on routes behind okta-oidc.auth. If parts of your app rely on Auth::check() being false for OIDC-only sessions, leave this off.

Creating Your Own

Implement Ua\LaravelOktaOidc\Contracts\UserBootstrapper:

Or extend SessionUserBootstrapper to keep the session claim behavior and add your own logic on top:

Then reference it in config:

Session Data

After a successful login, the following session keys are available:

Session Key Source Description
username Controller The resolved principal
okta.id_token Controller JWT ID token (used for federated logout)
okta.session_expires_at Controller ISO 8601 expiration timestamp
okta.name SessionUserBootstrapper User's display name
okta.email SessionUserBootstrapper User's email address
okta.raw_claims SessionUserBootstrapper Full array of OIDC claims

The first three are always set by the controller. The rest depend on your session_claims config and which bootstrapper you're using.

Session keys are configurable:

Middleware Behavior

The okta-oidc.auth middleware protects routes by checking for a valid OIDC session. It handles expired sessions differently based on the request type:

Branches are evaluated in this order; the first match wins:

Request Type Behavior
Inertia request (X-Inertia: true) Returns 409 with X-Inertia-Location header so the Inertia client triggers a full-page navigation. Safe methods point at login (and store the intended URL); unsafe methods point at the expired page.
JSON/AJAX request Returns 419 status with { "message": "...", "reauth_url": "..." } (any HTTP verb)
Safe HTML method (GET, HEAD, OPTIONS) Stores current URL as intended, redirects to login
Unsafe HTML method (POST, PUT, DELETE) Redirects to the expired page — does not replay the request

This prevents accidental form resubmission after session expiry.

Inertia.js Support

If you're using Inertia.js, the middleware automatically detects Inertia requests via the X-Inertia header and responds with HTTP 409 plus an X-Inertia-Location header. The Inertia client treats this as an external redirect and performs a full-page browser navigation — which is required to handle the redirect chain to Okta correctly. Detection is header-based, so the package does not depend on inertiajs/inertia-laravel.

Federated Logout

By default, logging out clears the local session and redirects to Okta's logout endpoint to end the Okta session. This prevents users from being silently re-authenticated on the next visit.

Disable it if you only want to clear the local session:

Configuration Reference

Publish with php artisan vendor:publish --tag=okta-oidc-config.

Key Default Description
driver 'okta' Socialite driver name
okta.base_url env('OKTA_BASE_URL') Okta org URL
okta.client_id env('OKTA_CLIENT_ID') OAuth client ID
okta.client_secret env('OKTA_CLIENT_SECRET') OAuth client secret
okta.redirect env('OKTA_REDIRECT_URI') Callback URL
okta.auth_server_id env('OKTA_AUTH_SERVER_ID') Auth server ID
routes.prefix 'auth/oidc' Route prefix
routes.middleware ['web'] Route middleware
routes.name_prefix 'okta-oidc.' Route name prefix
middleware_alias 'okta-oidc.auth' Middleware alias
scopes ['openid', 'profile', 'email'] OAuth scopes
principal_resolver UsernamePrincipalResolver::class Principal resolver class
user_bootstrapper SessionUserBootstrapper::class User bootstrapper class
hydrate_guard false Populate the auth guard with a request-scoped GenericUser from session claims
user_model env('OKTA_OIDC_USER_MODEL', 'App\\Models\\User') Eloquent user model
session_keys.principal 'username' Session key for principal
session_keys.id_token 'okta.id_token' Session key for ID token
session_keys.expires_at 'okta.session_expires_at' Session key for expiry
session_claims See above Claim-to-session mapping
redirects.after_login '/' Redirect after login
redirects.after_logout null Redirect after logout
messages.expired Session expired message Shown on expired page
messages.logged_out Signed out message Shown on logged-out page
expired_request_status 419 HTTP status for expired JSON responses
federated_logout true Enable Okta federated logout

Security Notes


All versions of okta-oidc with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/routing Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
laravel/socialite Version ^5.16
socialiteproviders/manager Version ^4.7
socialiteproviders/okta Version ^4.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ua/okta-oidc contains the following files

Loading the files please wait ...