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

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

spaces/oauth2-client
====================

OAuth 2.0 authentication for Mittwald SPACES

v2.0.0(7y ago)11.1k1MITPHP

Since Apr 5Pushed 7y ago7 watchersCompare

[ Source](https://github.com/mittwald/spaces-auth)[ Packagist](https://packagist.org/packages/spaces/oauth2-client)[ RSS](/packages/spaces-oauth2-client/feed)WikiDiscussions master Synced 2mo ago

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

SPACES OAuth2.0 authentication
==============================

[](#spaces-oauth20-authentication)

[![Build Status](https://camo.githubusercontent.com/f9d989c8c73efa8737dae4b1825426982d1527be5f3a8e9ef43c798747f66e9c/68747470733a2f2f7472617669732d63692e6f72672f6d69747477616c642f7370616365732d617574682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mittwald/spaces-auth)[![Packagist](https://camo.githubusercontent.com/bc23b24b0585d11067991e73bc1820e82e06f606e4b45c77705798f74c69b0dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370616365732f6f61757468322d636c69656e742e737667)](https://packagist.org/packages/spaces/oauth2-client)

Client library to integrate an OAuth2.0 authorization flow into PHP applications.

Usage
-----

[](#usage)

1. Provide your own implementation of the `Mw\Spaces\OAuth2\Context`interface:

    ```
    namespace Your\Namespace;

    class Context implements \Mw\Spaces\OAuth2\Context
    {
        public function getRedirectURI()
        {
            return "https://my-application.example/oauth-redir";
        }
    }

    ```

    Note that the `/oauth-redir` path needs to point to an application-specific OAuth2 redirection handler implemented by you.
2. Create the OAuth2.0 provider:

    ```
    $ctx = new \Your\Namespace\Context();
    $opts = new \Mw\Spaces\OAuth2\EnvironmentOptions($_SERVER);

    $provider = new \Mw\Spaces\OAuth2\SpacesProvider($opts, $ctx);

    ```
3. Next, retrieve the authorization URL and redirect your user there:

    ```
    $authorizationURL = $provider->getAuthorizationUrl();

    $_SESSION["spaces.de/auth/csrf"] = $provider->getState();

    header("Location: " . $authorizationURL);

    ```
4. The identity provider will prompt the user for their credentials, and - on success - will redirect the user back to your Redirect URI. When handling the redirected request, you'll need to retrieve the authorization code and check the CSRF value:

    ```
    $state = $_GET["state"];
    $code  = $_GET["code"];

    if ($_SESSION["spaces.de/auth/csrf"] != $state) {
        die("...");
    }

    ```

    After that, you can use the code to retrieve your access token:

    ```
    $accessToken = $provider->getAccessToken('authorization_code', [
        'code' => $code,
    ]);

    ```
5. Having the `$accessToken`, you can now (all while handling the redirected request) use that token to load the resource owner:

    ```
    try {
        $owner = $provider->getResourceOwner($accessToken);
        $ownerID = $accessToken->getResourceOwnerId();

        // synchronize local user using $owner
    } catch (\Mw\Spaces\OAuth2\Error\UserNotPresentException $err) {
        // user has no access to project
        // deny login
    }

    ```

    Use the data in the `$owner` object to construct a new local user (or update an existing record). You can store the *Resource Owner ID* for each created user to match them later on.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~146 days

Total

2

Last Release

2814d ago

Major Versions

v1.0.0 → v2.0.02018-08-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f0cf4eb3d44bff50a8f8dd5a05062c98edaf6d078f16cfae2f41caeb1a5e72a?d=identicon)[mittwald-typo3](/maintainers/mittwald-typo3)

---

Top Contributors

[![martin-helmich](https://avatars.githubusercontent.com/u/2538958?v=4)](https://github.com/martin-helmich "martin-helmich (10 commits)")[![ins0](https://avatars.githubusercontent.com/u/2622534?v=4)](https://github.com/ins0 "ins0 (2 commits)")

---

Tags

identity-provideroauthoauth2oauth2-clientphpphp-library

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[league/oauth2-google

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

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

Integration with league/oauth2-client to provide services

83416.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)
