PHPackages                             openclerk/users - 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. openclerk/users

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

openclerk/users
===============

0.1.1(8y ago)01142PHP

Since Dec 8Pushed 8y ago1 watchersCompare

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

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

openclerk/users
===============

[](#openclerkusers)

A library for User management in Openclerk, supporting password, OpenID and OAuth2 login.

Installing
----------

[](#installing)

Include `openclerk/users` as a requirement in your project `composer.json`, and run `composer update` to install it into your project:

```
{
  "require": {
    "openclerk/users": "dev-master"
  },
  "repositories": [{
    "type": "vcs",
    "url": "https://github.com/openclerk/users"
  }]
}
```

Make sure that you run all of the migrations that can be discovered through [component-discovery](https://github.com/soundasleep/component-discovery); see the documentation on [openclerk/db](https://github.com/openclerk/db) for more information.

```
$migrations = new AllMigrations(db());
if ($migrations->hasPending(db())) {
  $migrations->install(db(), $logger);
}
```

Features
--------

[](#features)

1. Automatic session management
2. Autologin
3. Optionally require emails for all non-password users with `users_require_email` config parameter
4. Forgot password/reset password functionality
5. Users can optionally have multiple OpenID/OAuth2 identities and one password associated with an account

Using
-----

[](#using)

This project uses [openclerk/db](https://github.com/openclerk/db) for database management and [openclerk/config](https://github.com/openclerk/config) for config management.

First configure the component with site-specific values:

```
Openclerk\Config::merge(array(
  "users_require_email" => false,
  "user_password_reset_expiry" => "3 days",
  "user_password_salt" => "abc123",
  "autologin_expire_days" => 30,
  "openid_host" => "localhost",
  "oauth2_google_client_id" => "abc123.apps.googleusercontent.com",
  "oauth2_google_client_secret" => "abc123",
  "oauth2_facebook_app_id" => "1234567",
  "oauth2_facebook_app_secret" => "abc123",
));

session_start();
```

You can now register and login users using a variety of authentication methods. The component assumes that only one user can own any one email address, and that all users need to define an email address as their primary key.

```
// get current user
$user = Users\User::getInstance(db());

// logout any current user
Users\User::logout(db());

// get a user instance
$user = Users\User::findUser(db(), $user_id);
```

### Password

[](#password)

```
// signup
$user = Users\UserPassword::trySignup(db(), $email /* may not be null */, $password);
if ($user) {
  echo "Signed up successfully";
}

// login
$user = Users\UserPassword::tryLogin(db(), $email /* may not be null */, $password);
if ($user) {
  echo "Logged in successfully as $user";
  $user->persist(db());
}

// forgot password
$secret = Users\UserPassword::forgottenPassword(db(), $email);
echo "Secret = $secret\n";

// complete forgot password
Users\UserPassword::completePasswordReset(db(), $email, $secret, $new_password);

// add password to existing user
$user = Users\User::getInstance(db());
$result = Users\UserPassword::addPassword(db(), $user, $password);
```

### OpenID

[](#openid)

You need to set a redirect value for all the OpenID callbacks, normally the same URL as the current script.

```
// signup
$user = Users\UserOpenID::trySignup(db(), $email /* may be null */, $openid, "http://localhost/register.php");
if ($user) {
  echo "Signed up successfully";
}

// login
$user = Users\UserOpenID::tryLogin(db(), $openid, "http://localhost/login.php");
if ($user) {
  echo "Logged in successfully as $user";
  $user->persist(db());
}

// add identity to existing user
$user = Users\User::getInstance(db());
$result = Users\UserOpenID::addIdentity(db(), $user, $openid, "http://localhost/add.php");
```

### OAuth2

[](#oauth2)

For **Google OAuth2**, login to your [Google Developers Console](https://console.developers.google.com/project), create a new Project, and visit *APIs &amp; Auth*:

1. *APIs:* Enable *Contacts API* and *Google+ API*
2. *Credentials:* create a new *Client ID* of type web applicaton, setting your permissible *Redirect URI* to the login and redirect URLs used in your application. Use the generated *Client ID* and *Client Secret* in your site configuration (above).

For **Facebook OAuth2**, login to your [Facebook Developers Console](https://developers.facebook.com/apps/), create a new App, and visit the Dashboard page for this app to get your *App ID* and *App Secret*.

For **GitHub OAuth2**, [register a new GitHub application](https://github.com/settings/applications/new), and use the generated *Client ID* and *Client Secret* in your site configuration (above).

```
// signup
$user = Users\UserOAuth2::trySignup(db(), Users\OAuth2Providers::google("http://localhost/register.php"));
if ($user) {
  echo "Signed up successfully";
}

// login
$user = Users\UserOAuth2::tryLogin(db(), Users\OAuth2Providers::google("http://localhost/login.php"));
if ($user) {
  echo "Logged in successfully as $user";
  $user->persist(db());
}

// add identity to existing user
$user = Users\User::getInstance(db());
$result = Users\UserOAuth2::addIdentity(db(), $user, Users\OAuth2Providers::google("http://localhost/add.php"));
```

More OAuth2 providers provided by default will be coming soon.

Events
------

[](#events)

#### openid\_validate

[](#openid_validate)

Triggered when OpenID validation occurs, after the user has returned with an OpenID mode. If any event returns `false`, OpenID validation will be cancelled.

Event parameter: $light object

#### oauth2\_auth

[](#oauth2_auth)

Triggered when OpenID authentication occurs, after the user has returned with an OAuth2 code. If any event returns `false`, OpenID validation will be cancelled.

Event parameter: $provider object

#### user\_deleted

[](#user_deleted)

Triggered when a user is deleted through `User::delete()`.

TODO
----

[](#todo)

1. Track last\_login
2. Removing identities
3. Tests
4. Publish on Packagist
5. Add user names, other user properties
6. Documentation on adding additional user parameters
7. Documentation on autologin with cookies
8. How to add, change, remove email addresses
9. More events

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.2% 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 ~1008 days

Total

2

Last Release

3171d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ebbec5ccc867054461adebb7c5b6312f8256f989ef96b124892e6e89724afdb?d=identicon)[soundasleep](/maintainers/soundasleep)

---

Top Contributors

[![soundasleep](https://avatars.githubusercontent.com/u/3889656?v=4)](https://github.com/soundasleep "soundasleep (55 commits)")[![Pascal66](https://avatars.githubusercontent.com/u/3041616?v=4)](https://github.com/Pascal66 "Pascal66 (1 commits)")

### Embed Badge

![Health badge](/badges/openclerk-users/health.svg)

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

###  Alternatives

[league/oauth2-google

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

42121.2M118](/packages/league-oauth2-google)[knpuniversity/oauth2-client-bundle

Integration with league/oauth2-client to provide services

84016.7M61](/packages/knpuniversity-oauth2-client-bundle)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

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

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

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

1132.5M6](/packages/patrickbussmann-oauth2-apple)[microsoft/kiota-authentication-phpleague

Authentication provider for Kiota using the PHP League OAuth 2.0 client to authenticate against the Microsoft Identity platform

153.2M7](/packages/microsoft-kiota-authentication-phpleague)

PHPackages © 2026

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