PHPackages                             previewtechs/oauth2-client - 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. previewtechs/oauth2-client

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

previewtechs/oauth2-client
==========================

Official OAuth2 Client for Preview Technologies

v2.4(8y ago)02512MITPHPPHP &gt;=5.6.0

Since Apr 8Pushed 8y ago2 watchersCompare

[ Source](https://github.com/PreviewTechnologies/oauth2-client)[ Packagist](https://packagist.org/packages/previewtechs/oauth2-client)[ RSS](/packages/previewtechs-oauth2-client/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (4)Versions (12)Used By (0)

Previewtechs Provider for OAuth 2.0 Client
==========================================

[](#previewtechs-provider-for-oauth-20-client)

This package provides Preview Technologies Limited OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

[![Latest Stable Version](https://camo.githubusercontent.com/3fbafbf30f341efa176ab5dd5f8d04a91316ccaa28c4569cba680e843ae3e11e/68747470733a2f2f706f7365722e707567782e6f72672f7072657669657774656368732f6f61757468322d636c69656e742f762f737461626c65)](https://packagist.org/packages/previewtechs/oauth2-client)[![License](https://camo.githubusercontent.com/cc9bcd6d45562503ecf6bddfdf959ac3f24dc1204eb5258993073b40e571b21a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7072657669657774656368732f6f61757468322d636c69656e742e737667)](https://github.com/previewtechs/oauth2-client/blob/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/60571a0951c51a4763d5b4594b87ac96bc731db2f88b2511e939ee1eb1bacbe7/68747470733a2f2f6170692e7472617669732d63692e6f72672f50726576696577546563686e6f6c6f676965732f6f61757468322d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/PreviewTechnologies/oauth2-client)[![Code Coverage](https://camo.githubusercontent.com/b2c8af7c4270f1a34ff9b1d837c15d34102ef37f520e018431d3dbfde9fd5965/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50726576696577546563686e6f6c6f676965732f6f61757468322d636c69656e742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PreviewTechnologies/oauth2-client/?branch=master)[![Code Quality](https://camo.githubusercontent.com/38bd91ee62a1ce2e2f9a1758455fb7f7c4c892da95885d59a472d18b62cdd8a9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50726576696577546563686e6f6c6f676965732f6f61757468322d636c69656e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PreviewTechnologies/oauth2-client/?branch=master)

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

[](#installation)

To install, use composer:

```
composer require previewtechs/oauth2-client

```

Usage
-----

[](#usage)

Usage is the same as The League's OAuth client, using `\Previewtechs\Oauth2\Client\Provider` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new \Previewtechs\Oauth2\Client\Provider([
    'clientId' => '{previewtechs_client_id}',    // The client ID assigned to you by Preview Technologies
    'clientSecret' => '{previewtechs_client_secret}',   // The client secret assigned to you by Preview Technologies
    'redirectUri' => '{your_redirect_url}'
]);
```

For further usage of this package please refer to the [core package documentation on "Authorization Code Grant"](https://github.com/thephpleague/oauth2-client#usage).

To get a full list of scopes, please go to [List of available OAuth2.0 scopes](https://support.previewtechs.com/portal/kb/articles/list-of-available-oauth-2-0-scopes)

### Refreshing a Token

[](#refreshing-a-token)

```
$provider = new \Previewtechs\Oauth2\Client\Provider([
    'clientId' => '{previewtechs_client_id}',    // The client ID assigned to you by Preview Technologies
    'clientSecret' => '{previewtechs_client_secret}',   // The client secret assigned to you by Preview Technologies
    'redirectUri' => '{your_redirect_url}'
]);

$existingAccessToken = getAccessTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
    $newAccessToken = $provider->getAccessToken('refresh_token', [
        'refresh_token' => $existingAccessToken->getRefreshToken()
    ]);

    //Remove old and save new access token in your database
}
```

For further usage of this package please refer to the [core package documentation on "Refreshing a Token"](https://github.com/thephpleague/oauth2-client#refreshing-a-token).

### Complete Usage

[](#complete-usage)

```
