PHPackages                             mattcollins171/oauth2-osm - 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. mattcollins171/oauth2-osm

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

mattcollins171/oauth2-osm
=========================

OSM OAuth 2.0 support for the PHP League's OAuth 2.0 Client

1.5(4y ago)43.5k1[2 issues](https://github.com/mattcollins171/oauth2-osm/issues)MITPHP

Since Dec 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/mattcollins171/oauth2-osm)[ Packagist](https://packagist.org/packages/mattcollins171/oauth2-osm)[ RSS](/packages/mattcollins171-oauth2-osm/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

OSM Provider for OAuth 2.0 Client
=================================

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

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

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

[](#installation)

```
composer require mattcollins171/oauth2-osm

```

Usage
-----

[](#usage)

```
$osmProvider = new \mattcollins171\OAuth2\Client\Provider\Osm([
    'clientId'                => 'yourId',          // The client ID assigned to you by OSM
    'clientSecret'            => 'yourSecret',      // The client password assigned to you by OSM
    'redirectUri'             => 'yourRedirectUri'  // The return URL you specified for your app on OSM
]);

// Get authorization code
if (!isset($_GET['code'])) {
    // Options are optional, defaults to 'profile' only
    $options = ['scope' => 'profile postal_code payments:widget payments:shipping_address payments:billing_address'];
    // Get authorization URL
    $authorizationUrl = $osmProvider->getAuthorizationUrl($options);

    // Get state and store it to the session
    $_SESSION['oauth2state'] = $osmProvider->getState();

    // Redirect user to authorization URL
    header('Location: ' . $authorizationUrl);
    exit;
// Check for errors
} elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) {
    if (isset($_SESSION['oauth2state'])) {
        unset($_SESSION['oauth2state']);
    }
    exit('Invalid state');
} else {
    // Get access token
    try {
        $accessToken = $osmProvider->getAccessToken(
            'authorization_code',
            [
                'code' => $_GET['code']
            ]
        );
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }

    // Get resource owner
    try {
        $resourceOwner = $osmProvider->getResourceOwner($accessToken);
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }

    // Now you can store the results to session etc.
    $_SESSION['accessToken'] = $accessToken;
    $_SESSION['resourceOwner'] = $resourceOwner;

    var_dump(
        $resourceOwner->getId(),
        $resourceOwner->getName(),
        $resourceOwner->getPostalCode(),
        $resourceOwner->getEmail(),
        $resourceOwner->toArray()
    );
}
```

For more information see the PHP League's general usage examples.

Testing
-------

[](#testing)

```
$ ./vendor/bin/phpunit
```

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity27

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

Every ~83 days

Recently: every ~104 days

Total

6

Last Release

1575d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5212b7192f2001e3e812a73ee9aa55754c8a32e20cf0538e01f977bee6d4920?d=identicon)[mattcollins171](/maintainers/mattcollins171)

---

Top Contributors

[![matt-monopolyrun](https://avatars.githubusercontent.com/u/185404779?v=4)](https://github.com/matt-monopolyrun "matt-monopolyrun (1 commits)")

---

Tags

phpapiclientAuthenticationoauthoauth2authorizationosm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mattcollins171-oauth2-osm/health.svg)

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

###  Alternatives

[league/oauth2-google

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

42121.2M118](/packages/league-oauth2-google)[league/oauth2-facebook

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

32013.0M66](/packages/league-oauth2-facebook)[andalisolutions/oauth2-anaf

Anaf OAuth 2.0 support for the PHP League's OAuth 2.0 Client

194.1k](/packages/andalisolutions-oauth2-anaf)

PHPackages © 2026

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