PHPackages                             jbelien/oauth2-openstreetmap - 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. jbelien/oauth2-openstreetmap

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

jbelien/oauth2-openstreetmap
============================

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

0.1.3(6mo ago)322.3k↓27.9%1[1 PRs](https://github.com/jbelien/oauth2-openstreetmap/pulls)1MITPHPCI passing

Since Aug 15Pushed 1mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (4)Versions (7)Used By (1)

OpenStreetMap Provider for OAuth 2.0 Client
===========================================

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

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

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

[](#installation)

```
composer require jbelien/oauth2-OpenStreetMap
```

Usage
-----

[](#usage)

```
$OpenStreetMapProvider = new \JBelien\OAuth2\Client\Provider\OpenStreetMap([
    'clientId'     => 'yourId',          // The client ID assigned to you by OpenStreetMap.org
    'clientSecret' => 'yourSecret',      // The client password assigned to you by OpenStreetMap.org
    'redirectUri'  => 'yourRedirectUri', // The return URL you specified for your app on OpenStreetMap.org
    'dev'          => false              // Whether to use the OpenStreetMap test environment at https://master.apis.dev.openstreetmap.org/
]);

// Get authorization code
if (!isset($_GET['code'])) {
    // Options are optional, defaults to 'read_prefs' only
    $options = ['scope' => 'read_prefs read_gpx'];
    // Get authorization URL
    $authorizationUrl = $OpenStreetMapProvider->getAuthorizationUrl($options);

    // Get state and store it to the session
    $_SESSION['oauth2state'] = $OpenStreetMapProvider->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 = $OpenStreetMapProvider->getAccessToken(
            'authorization_code',
            [
                'code' => $_GET['code']
            ]
        );
    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
        exit($e->getMessage());
    }

    // Get resource owner
    try {
        $resourceOwner = $OpenStreetMapProvider->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->getDisplayName(),
        $resourceOwner->getAccountCreated(),
        $resourceOwner->getImage(),
        $resourceOwner->getChangesetsCount(),
        $resourceOwner->getLanguages(),
        $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/jbelien/oauth2-openstreetmap/blob/master/LICENSE) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance81

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76% 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 ~516 days

Total

4

Last Release

189d ago

### Community

Maintainers

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

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (38 commits)")[![jbelien](https://avatars.githubusercontent.com/u/1150563?v=4)](https://github.com/jbelien "jbelien (11 commits)")[![sgrossberndt](https://avatars.githubusercontent.com/u/3786510?v=4)](https://github.com/sgrossberndt "sgrossberndt (1 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationosmOpenStreetMap

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jbelien-oauth2-openstreetmap/health.svg)

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

###  Alternatives

[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)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)[omines/oauth2-gitlab

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

36721.5k13](/packages/omines-oauth2-gitlab)

PHPackages © 2026

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