PHPackages                             lupecode/oauth2-tdameritrade - 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. lupecode/oauth2-tdameritrade

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

lupecode/oauth2-tdameritrade
============================

TD Ameritrade OAuth 2.0 Client Provider for The PHP League OAuth2-Client.

5221[1 issues](https://github.com/LupeCode/oauth2-tdameritrade/issues)[2 PRs](https://github.com/LupeCode/oauth2-tdameritrade/pulls)PHP

Since Feb 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/LupeCode/oauth2-tdameritrade)[ Packagist](https://packagist.org/packages/lupecode/oauth2-tdameritrade)[ RSS](/packages/lupecode-oauth2-tdameritrade/feed)WikiDiscussions primary Synced 5d ago

READMEChangelogDependenciesVersions (3)Used By (0)

TD Ameritrade Provider for OAuth 2.0 Client
===========================================

[](#td-ameritrade-provider-for-oauth-20-client)

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

[![Build Status](https://camo.githubusercontent.com/1827b2af295c35d0817d9bdce64c5884f4bf224aac0352d70ed6315b6203389b/68747470733a2f2f7472617669732d63692e636f6d2f4c757065436f64652f6f61757468322d7464616d65726974726164652e7376673f6272616e63683d7072696d617279)](https://travis-ci.com/LupeCode/oauth2-tdameritrade)[![Codacy Badge](https://camo.githubusercontent.com/6ee778961bd3b435c0897e0cfda51b407a5ff2558784e2dc7c550d50b568dc15/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3261633563636264313932613435623338323862303436303264626133333534)](https://www.codacy.com/gh/LupeCode/oauth2-tdameritrade/dashboard)[![Codacy Badge](https://camo.githubusercontent.com/8d1156e1e84829f10e70854f2c0461691d066df957abf412c521e0c0ebb961db/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f436f7665726167652f3261633563636264313932613435623338323862303436303264626133333534)](https://www.codacy.com/gh/LupeCode/oauth2-tdameritrade/dashboard)

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

[](#installation)

To install, use composer:

```
composer require lupecode/oauth2-tdameritrade

```

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

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

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

```
$options = [
    'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
    'scope' => [] // array or string
    // note that TD Ameritrade is still developing their API,
    // and the scopes do not work correctly at the moment.
];

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

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

At the time of authoring this documentation, no scopes are required.

Testing
-------

[](#testing)

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

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

[](#contributing)

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

Credits
-------

[](#credits)

- [Joshua Lopez](https://github.com/jb-lopez)
- [All Contributors](https://github.com/LupeCode/oauth2-tdameritrade/contributors)

License
-------

[](#license)

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

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![jb-lopez](https://avatars.githubusercontent.com/u/8528028?v=4)](https://github.com/jb-lopez "jb-lopez (10 commits)")

### Embed Badge

![Health badge](/badges/lupecode-oauth2-tdameritrade/health.svg)

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

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

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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