PHPackages                             omines/oauth2-gitlab - 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. omines/oauth2-gitlab

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

omines/oauth2-gitlab
====================

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

3.8.1(1mo ago)36761.9k↓12.9%413MITPHPPHP &gt;=8.3CI passing

Since May 16Pushed 1mo ago4 watchersCompare

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

READMEChangelog (10)Dependencies (26)Versions (18)Used By (13)

GitLab Provider for OAuth 2.0 Client
====================================

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

[![Latest Version](https://camo.githubusercontent.com/1a3253643de05b7a00aecbb01286e3a27d91d7271babef702de04ca869a8ca1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6f6d696e65732f6f61757468322d6769746c61622e7376673f7374796c653d666c61742d737175617265)](https://github.com/omines/oauth2-gitlab/releases)[![Total Downloads](https://camo.githubusercontent.com/f95a71aeeacda4fc269b6fb3439d2ab029357730fbba196acdcbf8ee67423fe4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6d696e65732f6f61757468322d6769746c61622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/omines/oauth2-gitlab)[![test suite](https://github.com/omines/oauth2-gitlab/actions/workflows/ci.yaml/badge.svg)](https://github.com/omines/oauth2-gitlab/actions/workflows/ci.yaml)[![codecov](https://camo.githubusercontent.com/bb8b940503f5aa3c5e3f794fbcad069e2bf6ceb481912579c2560615ab65a501/68747470733a2f2f636f6465636f762e696f2f67682f6f6d696e65732f6f61757468322d6769746c61622f67726170682f62616467652e7376673f746f6b656e3d73417175394946615951)](https://codecov.io/gh/omines/oauth2-gitlab)[![Mutation testing badge](https://camo.githubusercontent.com/38798a7c8258378b16a7b0a9970aaa8e3eb2b979546640a4583c708b78cd2b05/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466f6d696e65732532466f61757468322d6769746c61622532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/omines/oauth2-gitlab/master)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

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

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

[](#installation)

To install, use composer:

```
composer require omines/oauth2-gitlab

```

Usage
-----

[](#usage)

Usage is similar to the basic OAuth client, using `\Omines\OAuth2\Client\Provider\Gitlab` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new \Omines\OAuth2\Client\Provider\Gitlab([
    'clientId'          => '{gitlab-client-id}',
    'clientSecret'      => '{gitlab-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url',
    'domain'            => 'https://my.gitlab.example',      // Optional base URL for self-hosted
]);

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->getName());

    } 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 GitLab authorization URL, you can specify the state and scopes your application may authorize.

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

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

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

### Performing API calls

[](#performing-api-calls)

Install [`m4tthumphrey/php-gitlab-api`](https://packagist.org/packages/m4tthumphrey/php-gitlab-api) to interact with the Gitlab API after authentication. Either connect manually:

```
$client = new \Gitlab\Client();
$client->setUrl('https://my.gitlab.url/api/v4/');
$client->authenticate($token->getToken(), \Gitlab\Client::AUTH_OAUTH_TOKEN);
```

Or call the `getApiClient` method on `GitlabResourceOwner` which does the same implicitly.

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

[](#contributing)

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

Credits
-------

[](#credits)

This code is a modified fork from the [official Github provider](https://github.com/thephpleague/oauth2-github) adapted for Gitlab use, so many credits go to [Steven Maguire](https://github.com/stevenmaguire).

Legal
-----

[](#legal)

This software was developed for internal use at [Omines Full Service Internetbureau](https://www.omines.nl/)in Eindhoven, the Netherlands. It is shared with the general public under the permissive MIT license, without any guarantee of fitness for any particular purpose. Refer to the included `LICENSE` file for more details.

###  Health Score

67

—

FairBetter than 99% of packages

Maintenance91

Actively maintained with recent releases

Popularity49

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 84.8% 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 ~242 days

Recently: every ~322 days

Total

16

Last Release

42d ago

Major Versions

1.1.0 → 2.0.02017-02-03

2.0.0 → 3.0.02017-05-31

PHP version history (7 changes)1.0.0-alpha.1PHP &gt;=5.5.0

1.1.0PHP &gt;=5.5.9

2.0.0PHP &gt;=5.6

3.2.0PHP &gt;=7.2

3.5.0PHP &gt;=8.0

3.6.0PHP &gt;=8.1

3.8.0PHP &gt;=8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1455673?v=4)[Niels Keurentjes](/maintainers/curry684)[@curry684](https://github.com/curry684)

---

Top Contributors

[![curry684](https://avatars.githubusercontent.com/u/1455673?v=4)](https://github.com/curry684 "curry684 (84 commits)")[![stevenmaguire](https://avatars.githubusercontent.com/u/1851973?v=4)](https://github.com/stevenmaguire "stevenmaguire (11 commits)")[![oyarzun](https://avatars.githubusercontent.com/u/2364606?v=4)](https://github.com/oyarzun "oyarzun (3 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (1 commits)")

---

Tags

gitlabgitlab-provideroauth2oauth2-clientphpclientoauthoauth2authorizationgitlabauthorisation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/omines-oauth2-gitlab/health.svg)

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

###  Alternatives

[stevenmaguire/oauth2-keycloak

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

2276.2M36](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

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

1142.7M10](/packages/patrickbussmann-oauth2-apple)[league/oauth2-instagram

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

661.1M43](/packages/league-oauth2-instagram)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.8M1](/packages/mollie-oauth2-mollie-php)[dalpras/oauth2-gotowebinar

LogMeIn GoToWebinar OAuth 2.0 Client Provider for the PHP League's OAuth 2.0 Client

1245.5k](/packages/dalpras-oauth2-gotowebinar)

PHPackages © 2026

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