PHPackages                             bogstag/oauth2-trakt - 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. bogstag/oauth2-trakt

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

bogstag/oauth2-trakt
====================

trakt.tv OAuth 2.0 Client Provider for The PHP League OAuth2-Client

v1.0.1(9y ago)42.1k↓20%1[3 PRs](https://github.com/Bogstag/oauth2-trakt/pulls)MITPHPPHP &gt;=5.6.0CI failing

Since Feb 25Pushed 1mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (4)Versions (8)Used By (0)

trakt.tv Provider for OAuth 2.0 Client
======================================

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

[![Latest Version](https://camo.githubusercontent.com/cefcd9926b989541c587e2c53e2a3179a74f053b02b4e950d880394d677c77f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f626f67737461672f6f61757468322d7472616b742e7376673f7374796c653d666c61742d737175617265)](https://github.com/bogstag/oauth2-trakt/releases)[![Build Status](https://camo.githubusercontent.com/64c081f8d60351482a14f976d06c7bca9f26878aa4aac07dd051739bd64a9e12/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f426f67737461672f6f61757468322d7472616b742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Bogstag/oauth2-trakt)[![Coverage Status](https://camo.githubusercontent.com/f04d2c415299aa3ef230f9cb7f86d568471c67363f8708afb26029ae39846fcb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f626f67737461672f6f61757468322d7472616b742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bogstag/oauth2-trakt/code-structure)[![Quality Score](https://camo.githubusercontent.com/3c60f63e61b24eb1b412e2ef3aa2bd484ad52eb40f57afdce5cd483cbefc835d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f626f67737461672f6f61757468322d7472616b742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bogstag/oauth2-trakt)[![StyleCI](https://camo.githubusercontent.com/cd1da760fbeb52f5740904fca70bc7114294d68ed833a5190f3a845b67a87884/68747470733a2f2f7374796c6563692e696f2f7265706f732f38333131363133362f736869656c643f6272616e63683d6d6173746572267374796c653d666c6174)](https://styleci.io/repos/83116136)[![Total Downloads](https://camo.githubusercontent.com/e6e561fc44c07607f30ef3bad84a93007ee9d8914d22fac7a9d750c60a1b1ff8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f67737461672f6f61757468322d7472616b742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bogstag/oauth2-trakt)[![Software License](https://camo.githubusercontent.com/2e24417d2b309360a3f062c04f938aade55a5e2afe24025341205ab2d18172d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626f67737461672f6f61757468322d7472616b742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bogstag/oauth2-trakt)

This package provides trakt.tv 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 bogstag/oauth2-trakt

```

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new Bogstag\OAuth2\Client\Provider\Trakt([
    'clientId'          => '{trakt-client-id}',
    'clientSecret'      => '{trakt-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->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();
}
```

Testing
-------

[](#testing)

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

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

[](#contributing)

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

Credits
-------

[](#credits)

- [Krister Bogstag](https://github.com/bogstag)
- [All Contributors](https://github.com/bogstag/oauth2-trakt/contributors)

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance59

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

3

Last Release

3359d ago

Major Versions

v0.1.0 → v1.02017-02-25

PHP version history (2 changes)v0.1.0PHP &gt;=5.5.0

v1.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8104765?v=4)[Bogstag](/maintainers/Bogstag)[@Bogstag](https://github.com/Bogstag)

---

Top Contributors

[![Bogstag](https://avatars.githubusercontent.com/u/8104765?v=4)](https://github.com/Bogstag "Bogstag (21 commits)")

---

Tags

authenticationauthorizationclientoauthoauth2trakttrakt-tvclientAuthenticationoauthoauth2authorizationtrakt

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bogstag-oauth2-trakt/health.svg)

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

###  Alternatives

[league/oauth2-google

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

41721.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)
