PHPackages                             pubpackage/okta-sdk-php - 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. [API Development](/categories/api)
4. /
5. pubpackage/okta-sdk-php

ActiveLibrary[API Development](/categories/api)

pubpackage/okta-sdk-php
=======================

PHP Wrapper for the Okta API

1.0.2(5y ago)010Apache-2.0PHPPHP ^7.2

Since Aug 9Pushed 5y agoCompare

[ Source](https://github.com/pubpackage/okta-sdk-php)[ Packagist](https://packagist.org/packages/pubpackage/okta-sdk-php)[ RSS](/packages/pubpackage-okta-sdk-php/feed)WikiDiscussions develop Synced 1w ago

READMEChangelog (3)Dependencies (18)Versions (5)Used By (0)

Okta PHP SDK
============

[](#okta-php-sdk)

[![Build Status](https://camo.githubusercontent.com/e2b102e7a0c24485485a6e9a806a71e3249ae7eab1478acb1cacf47e945ebb3b/68747470733a2f2f6170692e7472617669732d63692e6f72672f6f6b74612f6f6b74612d73646b2d7068702e7376673f6272616e63683d6d61737465722c646576656c6f70)](https://travis-ci.org/okta/okta-sdk-php)[![Codecov](https://camo.githubusercontent.com/238c9e35ed4e00bf78161e4ec00b22321f55620c9af9eb1becc572a9aeb7f7ce/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6f6b74612f6f6b74612d73646b2d7068702e737667)](https://codecov.io/github/okta/okta-sdk-php)[![License](https://camo.githubusercontent.com/d95e59c7b6ccd886d38925d4ae4420499aceb3d1d13409a86f93cd994f334493/68747470733a2f2f706f7365722e707567782e6f72672f6f6b74612f73646b2f6c6963656e73652e737667)](https://packagist.org/packages/okta/sdk)[![Support](https://camo.githubusercontent.com/ee2a88800105c9fe413810b3dfd66d47236909b19bac3ca06d6311a2a026fff9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737570706f72742d446576656c6f706572253230466f72756d2d626c75652e737667)](https://devforum.okta.com/)

Installation
------------

[](#installation)

**okta-sdk-php** is available on Packagist as the [okta/sdk](http://packagist.org/packages/okta/sdk) package.

Run `composer require okta/sdk` from the root of your project in terminal, and you are done.

Client Initialization
---------------------

[](#client-initialization)

Once you have the SDK installed in your project, you will need to instantiate a Client object. We follow the builder pattern for building a Client. You can create a Client by calling the ClientBuilder and relying on the ~/.okta/okta .yaml file for the settings

```
$client = (new \Okta\ClientBuilder())
            ->build();
```

By default, The client builder will look for a file in your home directory with the Okta properties you want to use. This file should be placed at `~/.okta/okta.yaml`. If at this location, you do not need to define the location during initialization. If you are unable to place the file there, or you are on a Windows based machine, you will have to define the location of this file manually if you want to use the file.

```
$client = (new \Okta\ClientBuilder())
            ->setConfigFileLocation('path/to/okta.yaml')
            ->build();
```

If you need to override any of the defaults from your `~/.okta/okta.yaml` file, or you do not have one, you can set the properties on the client builder directly. The minimum required properties are your token and organization url.

```
$client = (new \Okta\ClientBuilder())
            ->setToken('YourApiToken')
            ->setOrganizationUrl('https://dev-123456.oktapreview.com')
            ->build();
```

### Changing your Http Client Instance

[](#changing-your-http-client-instance)

The Okta PHP SDK follows PSR-7 standards for HTTP Messages. We are using Httplug which allows you to change out to any PSR-7 compliant Http Client. Create a new instance of a `Http\Client\HttpClient`implementation and pass it into the client builder.

```
$client = (new \Okta\ClientBuilder())
            ->setHttpClient(new Http\Client\HttpClient())
            ->build();
```

### OAuth 2.0

[](#oauth-20)

Okta allows you to interact with Okta APIs using scoped OAuth 2.0 access tokens. Each access token enables the bearer to perform specific actions on specific Okta endpoints, with that ability controlled by which scopes the access token contains.

This SDK supports this feature only for service-to-service applications. Check out [our guides](https://developer.okta.com/docs/guides/implement-oauth-for-okta/overview/) to learn more about how to register a new service application using a private and public key pair.

When using this approach you won't need an API Token because the SDK will request an access token for you. In order to use OAuth 2.0, construct a client instance by passing the following parameters:

```
$client = (new \Okta\ClientBuilder)
            ->setAuthorizationMode(new \Okta\Utilities\AuthorizationMode(\Okta\Utilities\AuthorizationMode::PRIVATE_KEY))
            ->setClientId({{clientId}})
            ->setScopes("okta.users.read okta.apps.read")
            ->setPrivateKey("{{PEM PRIVATE KEY BLOCK}}")
            ->build();
```

Users
-----

[](#users)

### Finding a user by id

[](#finding-a-user-by-id)

```
$user = new \Okta\Users\User();
$foundUser = $user->get('00uak5dkxjhg4AQ230h7');
dump($foundUser);
```

### Finding a user by email

[](#finding-a-user-by-email)

```
$user = new \Okta\Users\User();
$foundUser = $user->get('email@example.com');
dump($foundUser);
```

### Creating a User

[](#creating-a-user)

```
$user = new \Okta\Users\User();
$profile = new \Okta\Users\UserProfile();

$profile->setFirstName('John')
    ->setLastName('User')
    ->setLogin('auser@example.com')
    ->setEmail('auser@example.com');
$user->setProfile($profile);

$credentials = new \Okta\Users\Credentials();

$password = new \Okta\Users\Password();
$password->setPassword('Abcd1234!');

$recoveryQuestion = new \Okta\Users\RecoveryQuestion();
$recoveryQuestion->setQuestion('What Language do I write in?')
    ->setAnswer('PHP!');

$provider = new \Okta\Users\Provider();
$provider->setName('OKTA')
    ->setType('OKTA');

$credentials->setPassword($password);
$credentials->setRecoveryQuestion($recoveryQuestion);
$credentials->setProvider($provider);

$user->setCredentials($credentials);

$user->setGroupIds([
    '00gajavp1anBX8svy0h7',
    '00gajb08d19WCvbsC0h7'
]);

$user->create();
```

### Update user profile

[](#update-user-profile)

Our SDK allows you to fill in the default profile fields, as well as other dynamic fields that you create in your profile.

```
$user = new \Okta\Users\User();
    $foundUser = $user->get('00uak5dkxjhg4AQ230h7');
    $profile = $foundUser->getProfile();
    $profile->middleName = 'Middle Name';
    $profile->someField = 'Just Testing Field';
    $foundUser->setProfile($profile);
    $foundUser->save();
```

Pagination and Collections
--------------------------

[](#pagination-and-collections)

All of our calls that return a set of items will return a Collection object. The collection object we built on top of is the tightenco/collect object.

### Getting all users

[](#getting-all-users)

```
$users = (new \Okta\Okta)->getUsers();

// get the first user in the collection
$firstUser = $users->first();
```

### Narrowing Responses

[](#narrowing-responses)

To start at the second entry and get the next two items:

```
$users = (new \Okta\Okta)->getUsers(['query' => ['limit' = 2, 'after' = 2]]);
```

Caching
-------

[](#caching)

The Okta PHP SDK allows any resource with a self link to be cached by default. The SDK uses any PSR-6 caching adaptor that you would like to use. By default, we ship with the [filesystem cache pool](https://github.com/php-cache/filesystem-adapter) with the [flysystem memory adaptor](https://github.com/thephpleague/flysystem-memory). By doing this, there is no need to configure anything, however, if you would like to run with your own Cache strategy, or change how the default works, you are able to swap out the Cache Manager. Create a new Cache Manager that extends the base `\Okta\Cache\CacheManager` class, and call the parent `setCachePool()` method. This should be called with an instance of a PSR-6 compliant cache pool implementation. Once created, you can swap out the manager using the `ClientBuilder` class

```
$clientBuilder = new ClientBuilder();
        $clientBuilder->setCacheManager(new MyCacheManager());
        $client = $clientBuilder->build();
```

### Contents of the okta.yaml File

[](#contents-of-the-oktayaml-file)

```
okta:
  client:
    orgUrl: "https://{yourOktaDomain}"
    token: "{token}"
```

When you use OAuth 2.0 the full YAML configuration looks like:

```
okta:
  client:
    connectionTimeout: 30 # seconds
    orgUrl: "https://{yourOktaDomain}"
    proxy:
      port: null
      host: null
      username: null
      password: null
    authorizationMode: "PrivateKey"
    clientId: "{yourClientId}"
    Scopes:
      - scope.1
      - scope.2
    PrivateKey: "{PEM PRIVATE KEY}"
    requestTimeout: 0 # seconds
    rateLimit:
      maxRetries: 4
```

> You can pass the path to your private key pem file as well instead of copying the pem string into the YAML configuration E.g `PrivateKey: /Path/to/privateKey.pem`

For information on what can go into the query property, visit [our documentation](https://developer.okta.com/docs/api/resources/users.html#list-users)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

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 ~0 days

Total

3

Last Release

1918d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e4e998eb6be6061038eb443bc91c16aa933d6147b625ab60d24b76096d43486?d=identicon)[pubpackage](/maintainers/pubpackage)

---

Top Contributors

[![bretterer](https://avatars.githubusercontent.com/u/1906920?v=4)](https://github.com/bretterer "bretterer (180 commits)")[![vijetmahabaleshwar-okta](https://avatars.githubusercontent.com/u/27521424?v=4)](https://github.com/vijetmahabaleshwar-okta "vijetmahabaleshwar-okta (14 commits)")[![lboyette-okta](https://avatars.githubusercontent.com/u/6387101?v=4)](https://github.com/lboyette-okta "lboyette-okta (8 commits)")[![pubpackage](https://avatars.githubusercontent.com/u/63796537?v=4)](https://github.com/pubpackage "pubpackage (3 commits)")[![nbarbettini](https://avatars.githubusercontent.com/u/7525482?v=4)](https://github.com/nbarbettini "nbarbettini (1 commits)")[![joelfranusic-okta](https://avatars.githubusercontent.com/u/8584286?v=4)](https://github.com/joelfranusic-okta "joelfranusic-okta (1 commits)")[![rsanchez](https://avatars.githubusercontent.com/u/227340?v=4)](https://github.com/rsanchez "rsanchez (1 commits)")[![shiqiyang-okta](https://avatars.githubusercontent.com/u/11919365?v=4)](https://github.com/shiqiyang-okta "shiqiyang-okta (1 commits)")[![coderintherye](https://avatars.githubusercontent.com/u/313805?v=4)](https://github.com/coderintherye "coderintherye (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/pubpackage-okta-sdk-php/health.svg)

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)

PHPackages © 2026

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