PHPackages                             cloudadic/twin23-oauth2-php-sdk - 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. cloudadic/twin23-oauth2-php-sdk

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

cloudadic/twin23-oauth2-php-sdk
===============================

v1.0(9y ago)020PHPPHP &gt;=5.5

Since Mar 30Pushed 8y ago3 watchersCompare

[ Source](https://github.com/cloudadic/twin23-oauth2-php-sdk)[ Packagist](https://packagist.org/packages/cloudadic/twin23-oauth2-php-sdk)[ Docs](https://www.twin23.com/)[ RSS](/packages/cloudadic-twin23-oauth2-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Twin23 OAuth 2.0 Client
=======================

[](#twin23-oauth-20-client)

This package makes it simple to integrate your application with [Twin23 OAuth 2.0](http://oauth.net/2/) service.

---

This package is compliant with [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md), [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md), and [PSR-7](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md). If you notice compliance oversights, please send a patch via pull request. If you're interesting in contributing to this library, please take a look at our [contributing guidelines](CONTRIBUTING.md).

Requirements
------------

[](#requirements)

The following versions of PHP are supported.

- PHP 5.5
- PHP 5.6
- PHP 7.0
- PHP 7.1
- HHVM

Install
-------

[](#install)

Via Composer

```
$ composer require cloudadic/twin23-oauth2-php-sdk
```

### OR

[](#or)

Add the following line to your composer.json

```
"cloudadic/twin23-oauth2-php-sdk":"*"
```

### Authorization Code Grant

[](#authorization-code-grant)

The authorization code grant type is the most common grant type used when authenticating users with a third-party service. This grant type utilizes a client (this library), a server (the service provider), and a resource owner (the user with credentials to a protected—or owned—resource) to request access to resources owned by the user. This is often referred to as *3-legged OAuth*, since there are three parties involved.

Now, for users who you don't have an account on Twin23, they'll be asked to put in their user info. Once fill out the form they are good to get logged-in.

#### Here's how you can configure your client.

[](#heres-how-you-can-configure-your-client)

```
// In order to get your OAuth 2 credentials you need to register your app at

$client = new Twin23\OAuth2\Client([
    // The client ID assigned to you by the provided
    'client_id' => 'YOUR_CLIENT_ID',
    // The client secret provided
    'client_secret' => 'YOUR_CLIENT_SECRET',
    // Redirect URL
    'redirect_uri' => 'http://my.website.com/redirect-page',
    // Permissions to the data that you would like to retrieve
    'scope' => ['name', 'email', 'photo', 'phone']
]);
```

#### Generate Authorization URL

[](#generate-authorization-url)

```
// Fetch the authorization URL. You can assign this to link on your web page.
$authorizationUrl = $client->getAuthorizationUrl();
```

#### Generate Access Token

[](#generate-access-token)

```
if (!empty($_GET['code'])) {
    try {

        // Try to get an access token using the authorization code grant.
        $accessToken = $client->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

        // We have an access token, which we may use in authenticated
        // requests against the service provider's API.
        echo 'Access Token: ' . $accessToken->getToken() . "";
        echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "";
        echo 'Expired in: ' . $accessToken->getExpires() . "";
        echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "";

        // Using the access token, we may look up details about the user

    } catch (\Twin23\Exception\ResponseException $e) {

        // Failed to get the access token or user details.
        exit($e->getMessage());

    }

}
```

### Refreshing a Token

[](#refreshing-a-token)

Once your application is authorized, you can refresh an expired token using a refresh token rather than going through the entire process of obtaining a brand new token. To do so, simply reuse this refresh token from your data store to request a refresh.

```
$existingAccessToken = $client->getAccessToken('authorization_code', [
    'code' => $code
]);

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

    // Purge old access token and store new access token to your data store.
}
```

Get Identity Info
-----------------

[](#get-identity-info)

```
$identity = $client->getIdentity($accessToken->getToken());
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/cloudadic/twin23-oauth2-php-sdk/blob/master/LICENSE) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

3328d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/942e30897e453d260236b53bb7d75225ee9b0864982ddf717201506d69dd0ea6?d=identicon)[miradnan](/maintainers/miradnan)

---

Top Contributors

[![miradnan](https://avatars.githubusercontent.com/u/397415?v=4)](https://github.com/miradnan "miradnan (49 commits)")

---

Tags

Twin23Twin23 OAuth2 PHP SDK

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cloudadic-twin23-oauth2-php-sdk/health.svg)

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

###  Alternatives

[josiasmontag/laravel-recaptchav3

Recaptcha V3 for Laravel package

2641.6M2](/packages/josiasmontag-laravel-recaptchav3)[rahul900day/laravel-captcha

Different types of Captcha implementation for Laravel Application.

10715.9k](/packages/rahul900day-laravel-captcha)[simplesamlphp/simplesamlphp-module-oidc

A SimpleSAMLphp module adding support for the OpenID Connect protocol

5016.9k1](/packages/simplesamlphp-simplesamlphp-module-oidc)[kinde-oss/kinde-auth-php

Kinde PHP SDK for authentication

2369.5k3](/packages/kinde-oss-kinde-auth-php)[descope/descope-php

Descope SDK for PHP

3814.0k](/packages/descope-descope-php)[njoguamos/laravel-turnstile

A laravel wrapper for https://developers.cloudflare.com/turnstile/

2315.9k2](/packages/njoguamos-laravel-turnstile)

PHPackages © 2026

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