PHPackages                             illuminati0n/oauth2-linkedin - 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. illuminati0n/oauth2-linkedin

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

illuminati0n/oauth2-linkedin
============================

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

1.0.4(2y ago)0601MITPHP

Since Apr 17Pushed 2y agoCompare

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

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

LinkedIn Provider for OAuth 2.0 Client
======================================

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

[![Latest Version](https://camo.githubusercontent.com/951c807acb1c069d48d42c6d0bd808ba213cf063e27641f38bddf52127d31e9c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7468657068706c65616775652f6f61757468322d6c696e6b6564696e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/thephpleague/oauth2-linkedin/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/3b11da95fd3bbbc113e6920f0933cc6d3ee263ea993071f3f07afbdcca6939a0/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468657068706c65616775652f6f61757468322d6c696e6b6564696e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/thephpleague/oauth2-linkedin)[![Coverage Status](https://camo.githubusercontent.com/f5d8d40951a55508cdaead72bf1ff80bd611b67a0e6e3b3b84cacca73ca8ac3c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7468657068706c65616775652f6f61757468322d6c696e6b6564696e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/oauth2-linkedin/code-structure)[![Quality Score](https://camo.githubusercontent.com/c6c0ce4bfef7719abcf7fb6e47dd46ec49734672c57c15c2a568b9719ec39705/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468657068706c65616775652f6f61757468322d6c696e6b6564696e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/oauth2-linkedin)[![Total Downloads](https://camo.githubusercontent.com/6ed3a9da08fffec31afca4bbdf753567f124421bfec3f46e3d12ba53eeee4159/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f6f61757468322d6c696e6b6564696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/oauth2-linkedin)

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

Before You Begin
----------------

[](#before-you-begin)

> The LinkedIn API has been largely closed off and is only available to approved LinkedIn developers. You can request authorization here -

You may be able to successfully obtain Access Tokens using this package and still not be authorized to access some resources available in the API.

If you encounter the following, or something similar, this policy is being enforced.

```
{
    "serviceErrorCode": 100,
    "message": "Not enough permissions to access: GET /me",
    "status": 403
}

```

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

[](#installation)

To install, use composer:

```
composer require illuminati0n/oauth2-linkedin

```

Usage
-----

[](#usage)

Usage is the same as The League's OAuth client, using `\illuminati0n\OAuth2\Client\Provider\LinkedIn` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

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

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: '.$authUrl);
    exit;

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

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

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

    // Optional: Now you have a token you can look up a users profile data
    try {

        // We got an access token, let's now get the user's details
        $user = $provider->getResourceOwner($token);

        // Use these details to create a new profile
        printf('Hello %s!', $user->getFirstName());

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}
```

### Managing Scopes

[](#managing-scopes)

When creating your LinkedIn authorization URL, you can specify the state and scopes your application may authorize.

```
$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    'scope' => ['r_liteprofile','r_emailaddress'] // array or string
];

$authorizationUrl = $provider->getAuthorizationUrl($options);
```

If neither are defined, the provider will utilize internal defaults.

At the time of authoring this documentation, the following scopes are available.

- r\_liteprofile (requested by default)
- r\_emailaddress (requested by default)
- r\_fullprofile
- w\_member\_social
- rw\_company\_admin

### Retrieving LinkedIn member information

[](#retrieving-linkedin-member-information)

When fetching resource owner details, the provider allows for an explicit list of fields to be returned, so long as they are allowed by the scopes used to retrieve the access token.

A default set of fields is provided. Overriding these defaults and defining a new set of fields is easy using the `withFields` method, which is a fluent method that returns the updated provider.

You can find a complete list of fields on LinkedIn's Developer Documentation:

- [For r\_liteprofile](https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile/basic-profile).
- [For r\_fullprofile](https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile/full-profile).

```
$fields = [
    'id', 'firstName', 'lastName', 'maidenName',
    'headline', 'vanityName', 'birthDate', 'educations'
];

$provider = $provider->withFields($fields);
$member = $provider->getResourceOwner($token);

// or in one line...

$member = $provider->withFields($fields)->getResourceOwner($token);
```

The `getResourceOwner` will return an instance of `League\OAuth2\Client\Provider\LinkedInResourceOwner` which has some helpful getter methods to access basic member details.

For more customization and control, the `LinkedInResourceOwner` object also offers a `getAttribute` method which accepts a string to access specific attributes that may not have a getter method explicitly defined.

```
$firstName = $member->getFirstName();
$birthDate = $member->getAttribute('birthDate');
```

#### A note about obtaining the resource owner's email address

[](#a-note-about-obtaining-the-resource-owners-email-address)

> The email has to be fetched by the provider in a separate request, it is not one of the profile fields.

When getting the resource owner a second request to fetch the email address will always be attempted. This request will fail silently (and `getEmail()` will return `null`) if the access token provided was not issued with the `r_emailaddress` scope.

```
$member = $provider->getResourceOwner($token);
$email = $member->getEmail();
```

You can also attempt to fetch the email in a separate request. This request will fail and throw an exception if the access token provided was not issued with the `r_emailaddress` scope.

```
$emailAddress = $provider->getResourceOwnerEmail($token);
```

### Refresh Tokens

[](#refresh-tokens)

> LinkedIn has introduced Refresh Tokens with OAuth 2.0. This feature is currently available for a limited set of partners. It will be made GA in the near future. [Source](https://developer.linkedin.com/docs/Refresh-Tokens-with-OAuth-2)

If your LinkedIn Client ID is associated with a partner that supports refresh tokens, this package will help you access and work with Refresh Tokens.

```
$refreshToken = $token->getRefreshToken();
$refreshTokenExpiration = $token->getRefreshTokenExpires();

```

Testing
-------

[](#testing)

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

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

[](#contributing)

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

Credits
-------

[](#credits)

- [Steven Maguire](https://github.com/stevenmaguire)
- [All Contributors](https://github.com/thephpleague/oauth2-linkedin/contributors)

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.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 ~0 days

Total

5

Last Release

753d ago

### Community

Maintainers

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

---

Top Contributors

[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (58 commits)")[![illuminati0n](https://avatars.githubusercontent.com/u/5390485?v=4)](https://github.com/illuminati0n "illuminati0n (12 commits)")[![Addvilz](https://avatars.githubusercontent.com/u/1390347?v=4)](https://github.com/Addvilz "Addvilz (2 commits)")[![frankpde](https://avatars.githubusercontent.com/u/37749068?v=4)](https://github.com/frankpde "frankpde (1 commits)")[![iisisrael](https://avatars.githubusercontent.com/u/932987?v=4)](https://github.com/iisisrael "iisisrael (1 commits)")[![vyskocilpavel](https://avatars.githubusercontent.com/u/28349779?v=4)](https://github.com/vyskocilpavel "vyskocilpavel (1 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationlinkedin

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/illuminati0n-oauth2-linkedin/health.svg)

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

###  Alternatives

[stevenmaguire/oauth2-keycloak

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

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[league/oauth2-linkedin

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

863.9M33](/packages/league-oauth2-linkedin)[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)
