PHPackages                             cilogon/oauth2-orcid - 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. cilogon/oauth2-orcid

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

cilogon/oauth2-orcid
====================

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

2.0.0(3y ago)79.6k↓46.2%21NCSAPHPPHP &gt;=5.6.0

Since May 25Pushed 3y ago4 watchersCompare

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

READMEChangelog (10)Dependencies (6)Versions (13)Used By (1)

ORCID Provider for the OAuth 2.0 Client
=======================================

[](#orcid-provider-for-the-oauth-20-client)

[![License](https://camo.githubusercontent.com/e44a8bfabfab06b50445d653ef7b5f77646e8123976731f15f50b05fc1e099dd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e4353412d627269676874677265656e2e737667)](https://github.com/cilogon/oauth2-orcid/blob/master/LICENSE)[![Travis](https://camo.githubusercontent.com/dd5fb37ed66b475349b5b208d046b513af199a64547de54e12bb1ea2d93f0a96/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63696c6f676f6e2f6f61757468322d6f726369642f6d61737465722e737667)](https://travis-ci.org/cilogon/oauth2-orcid)[![Scrutinizer](https://camo.githubusercontent.com/d73f122dc7cd79e0a61f2d6cf6b9da1aa39556f4c09408ef8ad4bfab99b401de/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f63696c6f676f6e2f6f61757468322d6f726369642f6d61737465722e737667)](https://scrutinizer-ci.com/g/cilogon/oauth2-orcid/)[![Coveralls](https://camo.githubusercontent.com/76ce045ecddf100f9914bac18fb0138438ead91c6488331534cbd87750942937/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f63696c6f676f6e2f6f61757468322d6f726369642f6d61737465722e737667)](https://coveralls.io/github/cilogon/oauth2-orcid?branch=master)

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

[ORCID](https://orcid.org) provides a persistent digital identifier for researchers. See [Getting Started](https://members.orcid.org/api/getting-started) for information on integrating your application with ORCID. You will eventually need to [register your application](https://orcid.org/developer-tools) to get an ORCID client id and client secret for your integration.

This package is compliant with [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md) and [PSR-12](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md). If you notice compliance oversights, please send a patch via pull request.

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

[](#requirements)

The following versions of PHP are supported.

- PHP 7.1 (v1.x)
- PHP 7.2 (v1.x)
- PHP 7.3 (v1.x)
- PHP 7.4 (v2.x)
- PHP 8.0 (v2.x)
- PHP 8.1 (v2.x)

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

[](#installation)

To install, use composer:

```
composer require cilogon/oauth2-orcid

```

Usage
-----

[](#usage)

### Authorization Code Flow

[](#authorization-code-flow)

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

if (!empty($_GET['error'])) {

    // Got an error, probably user denied access
    exit('Got error: ' . $_GET['error'] .
         'Description: ' . $GET['error_description']);

} elseif (empty($_GET['code'])) {

    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    // Check given state against previously stored one to mitigate CSRF attack
    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

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

        // Print out the access token, which can be used in
        // authenticated requests against the service provider's API.
        echo '' . "\n";
        echo 'Token                  : ' . $token->getToken() . "\n";
        $expires = $token->getExpires();
        if (!is_null($expires)) {
            echo 'Expires                : ' . $token->getExpires();
            echo ($token->hasExpired() ? ' (expired)' : ' (active)') . "\n";
        }
        echo '' . "\n";

        // Using the access token, get the user's details
        $user = $provider->getResourceOwner($token);

        echo '' . "\n";
        echo 'User ID                : ' . $user->getId() . "\n";
        echo 'First name             : ' . $user->getGivenName() . "\n";   // or getFirstName()
        echo 'Last name              : ' . $user->getFamilyName() . "\n";  // or getLastName()
        echo 'Published name         : ' . $user->getName() . "\n";
        echo 'Also Known As          : ' . implode(',', $user->getOtherNames()) . "\n";
        echo 'Email                  : ' . $user->getEmail() . "\n";       // 'Primary' preferred
        echo 'Primary Email          : ' . $user->getPrimaryEmail() . "\n";// 'Primary' ONLY
        echo 'All Emails             : ' . implode(',', $user->getEmails()) . "\n";
        echo 'AuthnMethodRef         : ' . $user->getAmr() . "\n";         // Only for Member API
        echo '';

    } catch (Exception $e) {

        // Failed to get access token or user details
        exit('Something went wrong: ' . $e->getMessage());

    }
}
```

### Sandbox vs Production

[](#sandbox-vs-production)

In order to authenticate ORCID users and read associated attributes, you would typically use the Production Registry. However, for special integrations, you may want to register for a [Sandbox application](https://orcid.org/content/register-client-application-sandbox). To use the Sandbox environment, set a 'sandbox' parameter to `true` when creating the provider.

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

Note that you can use this in combination with the Member API (below).

### Public API vs Member API

[](#public-api-vs-member-api)

If you are an [ORCID member](https://orcid.org/about/membership), you can use the Member API instead of the Public API. To use the Member API, set a 'member' parameter to `true` when creating the provider. The Member API provides an additional id\_token field 'amr' (AuthnMethodRef). The value is either 'mfa' for users who have enabled two-factor authentication on their ORCID account, or 'pwd' otherwise. When using the Public API, `getAmr()` returns `null`.

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

Note that you can use this in combination with the Sandbox environment (above).

### Refreshing a Token

[](#refreshing-a-token)

[Refreshing an ORCID token](https://members.orcid.org/api/oauth/refresh-tokens) requires the value of the current access token as the Bearer Token for authentication. So your application needs to use both the current access token AND the refresh token to get a new access token (and associated refresh token).

```
$accesstoken  = $token->getToken();
$refreshtoken = $token->getRefreshToken();
$newtoken = $provider->getAccessToken('refresh_token', [
    'refresh_token' => $refreshtoken,
], $accesstoken);
```

License
-------

[](#license)

The University of Illinois/NCSA Open Source License (NCSA). Please see [License File](https://github.com/cilogon/oauth2-orcid/blob/master/LICENSE) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% 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 ~173 days

Recently: every ~144 days

Total

12

Last Release

1379d ago

Major Versions

1.0.10 → 2.0.02022-08-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/0cf1c382d3acc207b6ffea4f30524a2b1bcf1453d7902dbcc48110d5f6afa953?d=identicon)[terrencegf](/maintainers/terrencegf)

---

Top Contributors

[![terrencegf](https://avatars.githubusercontent.com/u/135982?v=4)](https://github.com/terrencegf "terrencegf (42 commits)")[![ghalse](https://avatars.githubusercontent.com/u/7996633?v=4)](https://github.com/ghalse "ghalse (1 commits)")

---

Tags

clientAuthenticationoauthoauth2authorizationorcid

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/cilogon-oauth2-orcid/health.svg)

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

###  Alternatives

[league/oauth2-google

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

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

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

1132.5M6](/packages/patrickbussmann-oauth2-apple)[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)
