PHPackages                             socialiteproviders/okta - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. socialiteproviders/okta

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

socialiteproviders/okta
=======================

Okta OAuth2 Provider for Laravel Socialite

4.5.0(1y ago)113.8M—4.2%93MITPHPPHP ^8.0

Since Nov 21Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/SocialiteProviders/Okta)[ Packagist](https://packagist.org/packages/socialiteproviders/okta)[ RSS](/packages/socialiteproviders-okta/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (11)Used By (3)

Okta
====

[](#okta)

```
composer require socialiteproviders/okta
```

Installation &amp; Basic Usage
------------------------------

[](#installation--basic-usage)

Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.

### Add configuration to `config/services.php`

[](#add-configuration-to-configservicesphp)

```
'okta' => [
  'base_url' => env('OKTA_BASE_URL'),
  'client_id' => env('OKTA_CLIENT_ID'),
  'client_secret' => env('OKTA_CLIENT_SECRET'),
  'redirect' => env('OKTA_REDIRECT_URI')
],
```

#### Multi Tenant SSO

[](#multi-tenant-sso)

If you need to authenticate users from multiple okta instances, you can dynamically set the configuration values prior to calling the `redirect`/`user` methods. You'll still need to add the services entry as per above, but you can leave all the values as `null`.

```
$config = new \SocialiteProviders\Manager\Config(
    'client_id',
    'client_secret',
    route('okta.callback'),
    [
        'base_url' => 'https://1234.okta.com',
    ]
);

\Laravel\Socialite\Facades\Socialite::driver('okta')
    ->setConfig($config)
    ->redirect();
```

#### Custom Auth Server

[](#custom-auth-server)

If you're using Okta Developer you should set `auth_server_id` config option appropriately. It should be set to "default", or to the server id of your Custom Authorization Server.

For more information, see the [okta docs](https://developer.okta.com/docs/concepts/auth-servers/).

### Add provider event listener

[](#add-provider-event-listener)

#### Laravel 11+

[](#laravel-11)

In Laravel 11, the default `EventServiceProvider` provider was removed. Instead, add the listener using the `listen` method on the `Event` facade, in your `AppServiceProvider` `boot` method.

- Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.

```
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
    $event->extendSocialite('okta', \SocialiteProviders\Okta\Provider::class);
});
```

Laravel 10 or below Configure the package's listener to listen for `SocialiteWasCalled` events. Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.

```
protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \SocialiteProviders\Okta\OktaExtendSocialite::class.'@handle',
    ],
];
```

### Usage

[](#usage)

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

```
return Socialite::driver('okta')->redirect();
```

Store a local copy in your callback:

```
public function handleProviderCallback(\Illuminate\Http\Request $request)
{
    $user = Socialite::driver('okta')->user();
    $localUser = User::updateOrCreate(['email' => $user->email], [
        'email'         => $user->email,
        'name'          => $user->name,
        'token'         => $user->token,
        'id_token'      => $user->id_token,
        'refresh_token' => $user->refreshToken,
    ]);

    try {
        Auth::login($localUser);
    }
    catch (\Throwable $e) {
        return redirect('/login-okta');
    }

    return redirect('/home');
}
```

Generate the logout url from your controller:

```
public function logout(\Illuminate\Http\Request $request)
{
    $idToken = $request->user()->id_token;
    $logoutUrl = Socialite::driver('okta')->getLogoutUrl($idToken, URL::to('/'));
    Auth::logout();

    return redirect($logoutUrl);
}
```

#### Refresh Token

[](#refresh-token)

Using a refresh token allows an active user to maintain their session:

```
$localUser = Auth::user();
$response = (object) Socialite::driver('okta')
    ->setScopes(['offline_access'])
    ->getRefreshTokenResponse($localUser->refresh_token);

$localUser->token         = $response->access_token;
$localUser->refresh_token = $response->refresh_token;

$localUser->save();
Auth::setUser($localUser);
```

NOTE: obtaining a `refresh_token` requires the scope `offline_access` on the initial login. See additional documentation [here](https://developer.okta.com/docs/reference/api/oidc/#token).

#### Client Token

[](#client-token)

To obtain a client access token for authenticating to other apps without a user:

```
$response = (object) Socialite::driver('okta')->getClientAccessTokenResponse();
$token = $response->access_token;
```

NOTE: no caching of this token is performed. It's strongly suggested caching the token locally for its ttl

#### Revoke Token

[](#revoke-token)

Mark a token as revoked when checked against an introspection endpoint

```
$repo = Socialite::driver('okta');
$repo->revokeToken($token, 'access_token');
// verify against introspection endpoint
$state = $repo->introspectToken($token, 'access_token');
if($state['active']){...};
```

### Returned User fields

[](#returned-user-fields)

- `id`
- `email`
- `email_verified`
- `nickname`
- `name`
- `first_name`
- `last_name`
- `profileUrl`
- `address`
- `phone`

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance63

Regular maintenance activity

Popularity52

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~282 days

Recently: every ~248 days

Total

10

Last Release

557d ago

Major Versions

v1.1.0 → 4.0.02020-10-25

PHP version history (5 changes)v1.0.0PHP ^5.6 || ^7.0

4.0.0PHP ^7.2

4.1.0PHP ^7.2 || ^8.0

4.3.0PHP ^7.4 || ^8.0

4.4.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23558090?v=4)[Miguel Piedrafita](/maintainers/m1guelpf)[@m1guelpf](https://github.com/m1guelpf)

---

Top Contributors

[![lucasmichot](https://avatars.githubusercontent.com/u/513603?v=4)](https://github.com/lucasmichot "lucasmichot (16 commits)")[![atymic](https://avatars.githubusercontent.com/u/50683531?v=4)](https://github.com/atymic "atymic (12 commits)")[![clink-aaron](https://avatars.githubusercontent.com/u/42357661?v=4)](https://github.com/clink-aaron "clink-aaron (5 commits)")[![antonkomarev](https://avatars.githubusercontent.com/u/1849174?v=4)](https://github.com/antonkomarev "antonkomarev (2 commits)")[![jakeblatchford](https://avatars.githubusercontent.com/u/33793364?v=4)](https://github.com/jakeblatchford "jakeblatchford (1 commits)")[![kjiang14](https://avatars.githubusercontent.com/u/57103743?v=4)](https://github.com/kjiang14 "kjiang14 (1 commits)")[![kylerdmoore](https://avatars.githubusercontent.com/u/19496495?v=4)](https://github.com/kylerdmoore "kylerdmoore (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![maks-oleksyuk](https://avatars.githubusercontent.com/u/90793591?v=4)](https://github.com/maks-oleksyuk "maks-oleksyuk (1 commits)")[![Max13](https://avatars.githubusercontent.com/u/531249?v=4)](https://github.com/Max13 "Max13 (1 commits)")[![robiiinos](https://avatars.githubusercontent.com/u/16455953?v=4)](https://github.com/robiiinos "robiiinos (1 commits)")[![saundefined](https://avatars.githubusercontent.com/u/4685504?v=4)](https://github.com/saundefined "saundefined (1 commits)")[![chaseconey](https://avatars.githubusercontent.com/u/1449463?v=4)](https://github.com/chaseconey "chaseconey (1 commits)")[![cosmastech](https://avatars.githubusercontent.com/u/42181698?v=4)](https://github.com/cosmastech "cosmastech (1 commits)")[![faustbrian](https://avatars.githubusercontent.com/u/22145591?v=4)](https://github.com/faustbrian "faustbrian (1 commits)")

---

Tags

laraveloauthoauth1oauth2social-mediasocialitesocialite-providerslaravelprovideroauthsocialiteokta

### Embed Badge

![Health badge](/badges/socialiteproviders-okta/health.svg)

```
[![Health](https://phpackages.com/badges/socialiteproviders-okta/health.svg)](https://phpackages.com/packages/socialiteproviders-okta)
```

###  Alternatives

[socialiteproviders/microsoft

Microsoft OAuth2 Provider for Laravel Socialite

326.1M13](/packages/socialiteproviders-microsoft)[socialiteproviders/instagram

Instagram OAuth2 Provider for Laravel Socialite

421.9M5](/packages/socialiteproviders-instagram)[kovah/laravel-socialite-oidc

OpenID Connect OAuth2 Provider for Laravel Socialite

2073.7k](/packages/kovah-laravel-socialite-oidc)[socialiteproviders/kakao

Kakao OAuth2 Provider for Laravel Socialite

10484.7k4](/packages/socialiteproviders-kakao)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
