PHPackages                             waytohealth/oauth2-omron - 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. waytohealth/oauth2-omron

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

waytohealth/oauth2-omron
========================

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

v3.0.0(2y ago)06.8k↓21.4%[5 PRs](https://github.com/waytohealth/oauth2-omron/pulls)MITPHPPHP &gt;=5.6.0

Since Dec 31Pushed 2y ago3 watchersCompare

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

READMEChangelog (5)Dependencies (6)Versions (20)Used By (0)

Omron Provider for OAuth 2.0 Client
===================================

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

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

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.

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

[](#requirements)

The following versions of PHP are supported.

- PHP 5.6
- PHP 7.0
- PHP 7.1
- HHVM

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

[](#installation)

To install, use composer:

```
composer require waytohealth/oauth2-omron

```

Usage
-----

[](#usage)

### Authorization Code Grant

[](#authorization-code-grant)

```
use waytohealth\OAuth2\Client\Provider\Omron;

$provider = new Omron([
    'clientId'          => '{omron-oauth2-client-id}',
    'clientSecret'      => '{omron-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url'
]);

// start the session
session_start();

// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {

    // Fetch the authorization URL from the provider; this returns the
    // urlAuthorize option and generates and applies any necessary parameters
    // (e.g. state).
    $authorizationUrl = $provider->getAuthorizationUrl();

    // Get the state generated for you and store it to the session.
    $_SESSION['oauth2state'] = $provider->getState();

    // Redirect the user to the authorization URL.
    header('Location: ' . $authorizationUrl);
    exit;

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

} else {

    try {

        // Try to get an access token using the authorization code grant.
        $accessToken = $provider->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 $accessToken->getToken() . "\n";
        echo $accessToken->getRefreshToken() . "\n";
        echo $accessToken->getExpires() . "\n";
        echo ($accessToken->hasExpired() ? 'expired' : 'not expired') . "\n";

        // Using the access token, we may look up details about the
        // resource owner.
        $resourceOwner = $provider->getResourceOwner($accessToken);

        var_export($resourceOwner->toArray());

        // The provider provides a way to get an authenticated API request for
        // the service, using the access token; it returns an object conforming
        // to Psr\Http\Message\RequestInterface.
        $request = $provider->getAuthenticatedRequest(
            Withings::METHOD_GET,
            Withings::BASE_WITHINGS_API_URL . '/v2/user?action=getdevice',
            $accessToken,
            ['headers' => [Withings::HEADER_ACCEPT_LANG => 'en_US'], [Withings::HEADER_ACCEPT_LOCALE => 'en_US']]
            // Fitbit uses the Accept-Language for setting the unit system used
            // and setting Accept-Locale will return a translated response if available.
            // https://dev.fitbit.com/docs/basics/#localization
        );
        // Make the authenticated API request and get the parsed response.
        $response = $provider->getParsedResponse($request);

        // If you would like to get the response headers in addition to the response body, use:
        //$response = $provider->getResponse($request);
        //$headers = $response->getHeaders();
        //$parsedResponse = $provider->parseResponse($response);

    } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $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.

```
$provider = new waytohealth\OAuth2\Client\Provider\Omron([
    'clientId'          => '{omron-oauth2-client-id}',
    'clientSecret'      => '{omron-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url',
    'authHostname'      => 'https://oauth.omronwellness.com',
    'apiUrl'            => 'https://api.omronwellness.com/api/measurement'
]);

$existingAccessToken = getAccessTokenFromYourDataStore();

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

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

Testing
-------

[](#testing)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/waytohealth/oauth2-omron/blob/master/CONTRIBUTING.md) for details.

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 65.4% 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 ~205 days

Recently: every ~196 days

Total

9

Last Release

1051d ago

Major Versions

v1.0.1 → v2.0.02019-07-03

v0.0.1-alpha → v1.0.22021-05-07

v1.0.2 → v2.0.12021-05-19

v2.2.0 → v3.0.02023-07-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/3735b69d141bc99aa32600e9a0493cf1f592c27097407b8755717783fee409b9?d=identicon)[mcgrogan91](/maintainers/mcgrogan91)

---

Top Contributors

[![mcgrogan91](https://avatars.githubusercontent.com/u/3495617?v=4)](https://github.com/mcgrogan91 "mcgrogan91 (17 commits)")[![benirose](https://avatars.githubusercontent.com/u/2953531?v=4)](https://github.com/benirose "benirose (4 commits)")[![acleitner](https://avatars.githubusercontent.com/u/3340567?v=4)](https://github.com/acleitner "acleitner (3 commits)")[![lostfocus](https://avatars.githubusercontent.com/u/45055?v=4)](https://github.com/lostfocus "lostfocus (1 commits)")[![mkopinsky](https://avatars.githubusercontent.com/u/591435?v=4)](https://github.com/mkopinsky "mkopinsky (1 commits)")

---

Tags

clientAuthenticationoauthoauth2authorizationomron

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/waytohealth-oauth2-omron/health.svg)

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

###  Alternatives

[league/oauth2-google

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

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

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

18597.7k](/packages/cakedc-oauth2-cognito)

PHPackages © 2026

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