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

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

buddy-works/oauth2-client
=========================

Buddy Provider for the OAuth 2.0 Client

1.0.0(5y ago)01.0k↑1375%MITPHPPHP &gt;=7.2CI failing

Since Apr 1Pushed 5y ago6 watchersCompare

[ Source](https://github.com/buddy-works/oauth2-client)[ Packagist](https://packagist.org/packages/buddy-works/oauth2-client)[ RSS](/packages/buddy-works-oauth2-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

Buddy Provider for OAuth 2.0 Client
===================================

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

[![Latest Version](https://camo.githubusercontent.com/d7ccb23741240febf994418f60b5ce630f6280e226a0f28734b3a32fc2a81260/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f62756464792d776f726b732f6f61757468322d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/buddy-works/oauth2-client/releases)[![buddy branch](https://camo.githubusercontent.com/b6241c0d58028d12b245ec137b63379a99b2df7c1cdf97e75346deba02812eb6/68747470733a2f2f6170702e62756464792e776f726b732f62756464792d776f726b732f6f61757468322d636c69656e742f7265706f7369746f72792f6272616e63682f6d61737465722f62616467652e7376673f746f6b656e3d62653034653737636232316430653765363131383533653930336535323162613233336530316434363639396131653664633030663835613835336362646436 "buddy branch")](https://app.buddy.works/buddy-works/oauth2-client/repository/branch/master)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/cb91abc24f325179d09a005a900005ccf52f561d126c13348ffa5b46fadf3da3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62756464792d776f726b732f6f61757468322d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/buddy-works/oauth2-client)

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

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

[](#installation)

To install, use composer:

```
composer require buddy-works/oauth2-client

```

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new Buddy\OAuth2\Client\Provider\Buddy([
    'clientId'          => '{buddy-client-id}',
    'clientSecret'      => '{buddy-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url',
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

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

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $user->getNickname());

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}
```

### Managing Scopes

[](#managing-scopes)

When creating your Buddy authorization URL, you can specify the state and scopes your application may authorize.

```
use Buddy\OAuth2\Client\Provider\Buddy;

$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    'scope' => [Buddy::SCOPE_WORKSPACE, Buddy::REPOSITORY_READ] // array or string
];

$authorizationUrl = $provider->getAuthorizationUrl($options);
```

If neither are defined, the provider will utilize internal defaults.

At the time of authoring this documentation, the [following scopes are available](https://buddy.works/docs/api/getting-started/oauth2/introduction#supported-scopes).

- `WORKSPACE` Access to basic workspace information as well as the rights to manage members, groups and member permissions
- `PROJECT_DELETE` Permission to delete projects.
- `REPOSITORY_READ` Access to commits and repository content. Repository checkout is allowed, too.
- `REPOSITORY_WRITE` Permission to write in the repository. File deletion is allowed, too (contains REPOSITORY\_READ rights).
- `EXECUTION_INFO` Access to executions history.
- `EXECUTION_RUN` Permission to run and stop executions (contains EXECUTION\_INFO rights).
- `EXECUTION_MANAGE` Permission to add/edit pipelines (contains EXECUTION\_RUN rights).
- `USER_INFO` Access to base information of the authorized user.
- `USER_KEY` Access to public SSH keys of authorized user.
- `USER_EMAIL` Access to email list of authorized user.
- `INTEGRATION_INFO` Access to integration list of authorized user.
- `MEMBER_EMAIL` Access to contact info of workspace members.
- `MANAGE_EMAILS` Permission to view and mange user email addresses (contains USER\_EMAIL rights).
- `WEBHOOK_INFO` Access to webhooks info.
- `WEBHOOK_ADD` Permission to get and add webhooks.
- `WEBHOOK_MANAGE` Permission to add/edit and delete webhooks.
- `VARIABLE_ADD` Permission to get and add environment variables.
- `VARIABLE_INFO` Access to environment variables' info.
- `VARIABLE_MANAGE` Permission to add/edit and delete environment variables.

Testing
-------

[](#testing)

```
composer tests
```

Credits
-------

[](#credits)

- [Arkadiusz Kondas](https://github.com/akondas)
- [All Contributors](https://github.com/buddy-works/oauth2-client/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/buddy-works/oauth2-client/blob/master/LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

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

Every ~98 days

Total

4

Last Release

1946d ago

Major Versions

0.1.2 → 1.0.02021-01-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d00e1e73a4ff379162b943421469055929a95e7a6ce4c3808976dcc1fa28f4f?d=identicon)[akondas](/maintainers/akondas)

---

Top Contributors

[![akondas](https://avatars.githubusercontent.com/u/8239917?v=4)](https://github.com/akondas "akondas (5 commits)")

---

Tags

continuous-deploymentcontinuous-integrationoauth2-clientoauth2-providerphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/buddy-works-oauth2-client/health.svg)

```
[![Health](https://phpackages.com/badges/buddy-works-oauth2-client/health.svg)](https://phpackages.com/packages/buddy-works-oauth2-client)
```

###  Alternatives

[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

42121.2M118](/packages/league-oauth2-google)[knpuniversity/oauth2-client-bundle

Integration with league/oauth2-client to provide services

84016.7M61](/packages/knpuniversity-oauth2-client-bundle)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[microsoft/kiota-authentication-phpleague

Authentication provider for Kiota using the PHP League OAuth 2.0 client to authenticate against the Microsoft Identity platform

153.2M7](/packages/microsoft-kiota-authentication-phpleague)

PHPackages © 2026

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