PHPackages                             duncan3dc/oauth - 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. duncan3dc/oauth

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

duncan3dc/oauth
===============

Handles basic OAuth/OAuth2 authentication along with classes for common services

1.4.0(3y ago)067.0k1Apache-2.0PHPPHP ^7.2 || ^8.0CI failing

Since Jun 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/duncan3dc/oauth)[ Packagist](https://packagist.org/packages/duncan3dc/oauth)[ Docs](https://github.com/duncan3dc/php-oauth)[ RSS](/packages/duncan3dc-oauth/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (13)Used By (0)

oauth
=====

[](#oauth)

Handles non-web based OAuth/OAuth2 authentication along with providers for common services

[![Latest Stable Version](https://camo.githubusercontent.com/7cf0848e85bfe0d240a8ccf4909a19101fd03ededd3d058332589de9fde84cd3/68747470733a2f2f706f7365722e707567782e6f72672f64756e63616e3364632f6f617574682f76657273696f6e2e737667)](https://packagist.org/packages/duncan3dc/oauth)[![build](https://github.com/duncan3dc/oauth/workflows/.github/workflows/buildcheck.yml/badge.svg?branch=main)](https://github.com/duncan3dc/oauth/actions/workflows/buildcheck.yml)[![Coverage Status](https://camo.githubusercontent.com/cfbafcfd36b7c5c84aaf96285e4732e9e432b3826c3577c0446b977caa1489fe/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f64756e63616e3364632f6f617574682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/duncan3dc/oauth)

**I really don't think you will find these classes useful, if you proceed then don't say I didn't warn you**
You are likely looking for [thephpleague/oauth1-client](https://github.com/thephpleague/oauth1-client) or [thephpleague/oauth2-client](https://github.com/thephpleague/oauth2-client)

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

[](#requirements)

- These classes require use of the [sql-class](https://github.com/duncan3dc/sql-class) project (for storing authorised credentials)
- The active database must contain a table called oauth (or know about it via the definitions within the Sql class)
- The table must have the following schema

```
`type`      varchar(20),
`username`  varchar(100),
`state`     int(11),
`token`     varchar(100),
`secret`    varchar(100),
UNIQUE KEY `type, username` (`type`,`username`)

```

OAuth2
------

[](#oauth2)

The OAuth2 classes require manual intervention to get authorised initially, but once your token/secret are in the database they work like the OAuth classes.

Examples
--------

[](#examples)

Basic twitter example

```
use duncan3dc\OAuth\Twitter;
use duncan3dc\SqlClass\Sql;

Sql::addServer("twitter", [
    "hostname"  =>  "example.com",
    "username"  =>  "my_twitter_app",
    "password"  =>  "secret_password",
    "database"  =>  "twitter",
]);

$twitter = new Twitter([
    "username"  =>  "my_handle",
    "authkey"   =>  "XfHrRTY25FgkyqxDfbpe",
    "secret"    =>  "gwj8c29GHDWdphmQhGtHPx4GybwRfhXplT3CD0VG1n",
]);

# The authorise method returns null if we are already authorised. Otherwise it returns a url to grant at
if ($url = $twitter->authorise()) {
    throw new \Exception("Authorsation failed, grant permission here: " . $url);
}

$userData = $twitter->user("my_handle");
print_($userData);
```

If you have extended the Sql class (or are using an interface compatible project) you can have the OAuth classes use that class as so

```
use duncan3dc\OAuth\Twitter;
use MrCoder\MyCustom\Sql;

\duncan3dc\OAuth\Sql::useClass(Sql::class);

$twitter = new Twitter([
```

If your oauth table is not in the active database, then you can let the Sql class know where it is using the following

```
use duncan3dc\OAuth\Twitter;
use duncan3dc\SqlClass\Sql;

Sql::addServer("twitter", [
    "hostname"      =>  "example.com",
    "username"      =>  "my_twitter_app",
    "password"      =>  "secret_password",
    "database"      =>  "twitter",
    "definitions"   =>  ["oauth" => "my_other_database"],
]);

$twitter = new Twitter([
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity75

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 ~301 days

Recently: every ~704 days

Total

11

Last Release

1346d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

1.4.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/11dc66042513f11d1c99b1e6763f25dca84a3ff31cdbea3972b9b804a3d3d5e9?d=identicon)[duncan3dc](/maintainers/duncan3dc)

---

Top Contributors

[![duncan3dc](https://avatars.githubusercontent.com/u/546811?v=4)](https://github.com/duncan3dc "duncan3dc (42 commits)")

---

Tags

instagramoauthoauth2githubtwitterlovefilm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/duncan3dc-oauth/health.svg)

```
[![Health](https://phpackages.com/badges/duncan3dc-oauth/health.svg)](https://phpackages.com/packages/duncan3dc-oauth)
```

###  Alternatives

[hwi/oauth-bundle

Support for authenticating users using both OAuth1.0a and OAuth2 in Symfony.

2.4k21.5M69](/packages/hwi-oauth-bundle)[and/oauth

Simple and amazing OAuth library with many providers. Just try it out!

4645.2k2](/packages/and-oauth)[socialconnect/auth

Social Connect Auth Component

568845.4k5](/packages/socialconnect-auth)[league/oauth2-github

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

1122.1M42](/packages/league-oauth2-github)[league/oauth2-instagram

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

761.0M31](/packages/league-oauth2-instagram)[fof/oauth

Allow users to log in with GitHub, Facebook, Google, Discord, GitLab, LinkedIn, and more!

50118.7k41](/packages/fof-oauth)

PHPackages © 2026

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