Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Release 1.3.0 (#121)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Towers <[email protected]>
Co-authored-by: Andrea <[email protected]>
Co-authored-by: Kevin <[email protected]>
Co-authored-by: Vijet Mahabaleshwar <[email protected]>
  • Loading branch information
5 people authored Mar 3, 2021
1 parent 569ccd4 commit bd1dc57
Show file tree
Hide file tree
Showing 23 changed files with 3,869 additions and 1,108 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OKTA_CLIENT_CLIENTID=
OKTA_CLIENT_SCOPES=
OKTA_CLIENT_PRIVATEKEY=
24 changes: 24 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Mark stale issues and pull requests

on:
schedule:
- cron: "30 1 * * *"

jobs:
stale:

runs-on: ubuntu-latest

steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been marked stale because there has been no activity within the last 14 days. To keep this issue active, remove the `stale` label.'
stale-pr-message: 'This PR has been marked stale because there has been no activity within the last 28 days. To keep this PR active, remove the `stale` label.'
days-before-issue-stale: 14
days-before-pr-stale: 28
days-before-close: -1
exempt-issue-labels: 'no-stalebot'
exempt-pr-labels: 'no-stalebot'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
examples
phpunit.xml
.phpunit.result.cache
.env
.vscode
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ before_script:
- mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc
- mkdir -p ~/.okta
script:
- if [[ $TRAVIS_EVENT_TYPE != "cron" ]]; then vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml; fi
- if [[ $TRAVIS_EVENT_TYPE != "cron" ]]; then XDEBUG_MODE=coverage vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml; fi
- if [[ $TRAVIS_EVENT_TYPE = "cron" ]]; then bash ./scripts/cron-test.sh; fi
after_success:
- if [[ $COVERAGE = 'true' ]]; then bash <(curl -s https://codecov.io/bash); fi
Expand All @@ -31,7 +31,7 @@ deploy:
email: [email protected]
name: PHP Deployment Bot
on:
php: 7.1
php: 8.0
condition: "$DEPLOY_DOCS = true"
tags: true
- provider: pages
Expand All @@ -41,23 +41,23 @@ deploy:
email: [email protected]
name: PHP Deployment Bot
on:
php: 7.1
php: 8.0
condition: "$DEPLOY_DOCS = true"
branch: develop
matrix:
include:
- php: 7.2
env: SETUP=lowest
- php: 7.2
env: SETUP=stable
- php: 7.3
env: SETUP=lowest
- php: 7.3
env: SETUP=stable
- php: 7.4
env:
- COVERAGE=true
- SETUP=stable
- DEPLOY_DOCS=true
- php: 8.0
env:
- COVERAGE=true
- SETUP=stable
notifications:
slack:
if: type = cron
rooms:
secure: pPjnzjBbTuUFSMOKdJQfzQWk8XeCxCg7Y0cRds/DP0YRIDIPOOGzUTWdzJG4oKGmwVFmnlmqGBnC3JaufXmIj0wSw9p/YmAOV9cdaZ6ZaqpqghL6EnN2y3M5jMkmTq7A1vAAvPC8g/NLORiR4fOcgGLzNRgHVVRYIMPE840mWxpEnohfHB/8PquL2/wjlzBuPOJBieq9SAGxb25SPAwMTaP1vewX3CP/zT5IDqqeuULZzR94xNiVIkeYzniDjjmBMh1FYUXbUBhR08jUVLCuvUgk959fpowbWf4UcqwRmcnDGeGYTatvX36MbmLHRhOU1zRvMuMG+uOQwr7kWOqJya3mxcPf6IW0gwXs6TVvruInKjkhsZHyc5oVC4WKgWZ41cd+RRlLbRcLHIvALN1jhLFda/KLpfGUVGFwrVv61kPLGvExMIZMQCxNj7PIr5RZB8faYBfrT3hf2SvG4bDwhdzjc07lqzhGQWvCi12Rc0Yzmo+PuAA4crPCG2OfjAj1U4IyOznvuhXGMfHtQMy5ow6bW9w/q1HTMwNBtswY78hyTetf7FHYmEe29IUnL44Ecv/34FWuY+Hszb1KwPKVdx0g7D9gdWU6sZZSipNrhG84rYIIRTi0zSDlZBS0+0P7WQQsXRJCplQtxHOTgImWDzIXVzqX9kep/AvT0IiO4CY=
89 changes: 66 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Okta PHP SDK
# Okta PHP SDK

[![Build Status](https://api.travis-ci.org/okta/okta-sdk-php.svg?branch=master,develop)](https://travis-ci.org/okta/okta-sdk-php)
[![Build Status](https://api.travis-ci.org/okta/okta-sdk-php.svg?branch=master,develop)](https://travis-ci.org/okta/okta-sdk-php)
[![Codecov](https://img.shields.io/codecov/c/github/okta/okta-sdk-php.svg)](https://codecov.io/github/okta/okta-sdk-php)
[![License](https://poser.pugx.org/okta/sdk/license.svg)](https://packagist.org/packages/okta/sdk)
[![Support](https://img.shields.io/badge/support-Developer%20Forum-blue.svg)](https://devforum.okta.com/)
Expand All @@ -11,18 +11,18 @@
Run `composer require okta/sdk` from the root of your project in terminal, and you are done.

## Client Initialization
Once you have the SDK installed in your project, you will need to instantiate a Client object. We follow the builder
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
.yaml file for the settings

```php
$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
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.

```php
Expand All @@ -31,7 +31,7 @@ $client = (new \Okta\ClientBuilder())
->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
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.

```php
Expand All @@ -42,8 +42,8 @@ $client = (new \Okta\ClientBuilder())
```

### 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`
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.

```php
Expand All @@ -52,6 +52,24 @@ $client = (new \Okta\ClientBuilder())
->build();
```

### OAuth 2.0

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-serviceapp/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:

```php
$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
### Finding a user by id
```php
Expand All @@ -70,7 +88,7 @@ dump($foundUser);
### Creating a User
```php
$user = new \Okta\Users\User();
$profile = new \Okta\Users\Profile();
$profile = new \Okta\Users\UserProfile();

$profile->setFirstName('John')
->setLastName('User')
Expand Down Expand Up @@ -109,7 +127,7 @@ $user->create();
```

### 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
Our SDK allows you to fill in the default profile fields, as well as other dynamic fields that you create in your
profile.

```php
Expand All @@ -125,7 +143,7 @@ $user = new \Okta\Users\User();
## 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
```php
$users = (new \Okta\Okta)->getUsers();
Expand All @@ -141,12 +159,12 @@ $users = (new \Okta\Okta)->getUsers(['query' => ['limit' = 2, 'after' = 2]]);
```

## 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
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
Expand All @@ -158,13 +176,38 @@ $clientBuilder = new ClientBuilder();
```

### Contents of the okta.yaml File
```php
```yaml
okta:
client:
orgUrl: null
token: null
orgUrl: "https://{yourOktaDomain}"
token: "{token}"
```
For information on what can go into the query property, visit
[our documentation](https://developer.okta.com/docs/api/resources/users.html#list-users)
When you use OAuth 2.0 the full YAML configuration looks like:
```yaml
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)
25 changes: 14 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.3 | ^8.0",
"psr/http-message": "^1.0",
"php-http/client-common": "^1.1",
"php-http/httplug": "^1.1",
"php-http/message": "^1.5",
"php-http/discovery": "^1.2",
"php-http/curl-client": "^1.7",
"symfony/yaml": "^4.3",
"php-http/client-common": "^2.2",
"php-http/httplug": "^2.2",
"php-http/message": "^1.11",
"php-http/discovery": "^1.13",
"php-http/curl-client": "^2.2",
"symfony/yaml": "^3.2|^4.3",
"nesbot/carbon": "^2.0",
"tightenco/collect": "5.8.31",
"guzzlehttp/psr7": "^1.4",
"illuminate/collections": "8.29.0",
"guzzlehttp/psr7": "1.7.0",
"psr/cache": "^1.0",
"league/flysystem-memory": "^1.0",
"cache/filesystem-adapter": "^1.0"
"cache/filesystem-adapter": "^1.0",
"vlucas/phpdotenv": "^3.3|^4.1",
"lcobucci/jwt": "^4.0@alpha",
"http-interop/http-factory-guzzle": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "3.*",
"symfony/var-dumper": "^4.3",
"php-http/mock-client": "^1.0"
Expand Down
Loading

0 comments on commit bd1dc57

Please sign in to comment.