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

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

code-sphere/oauth
=================

OAuth2 client package for CodeSphere Accounts. Stateless identity, group membership, and team checks for all CodeSphere apps.

0362↓14.8%PHPCI passing

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/Code-Sphere-Development/oauth)[ Packagist](https://packagist.org/packages/code-sphere/oauth)[ RSS](/packages/code-sphere-oauth/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

code-sphere/oauth
=================

[](#code-sphereoauth)

Stateless OAuth2 client for CodeSphere Accounts. Drop-in single sign-on for all CodeSphere apps.

What it does
------------

[](#what-it-does)

- Implements the OAuth2 authorization code flow against `CodeSphere Accounts`.
- Stores **only** the minimum locally: `codesphere_id`, `access_token`, `refresh_token`, `token_expires_at`. **No name, email, or avatar in the local database.**
- Caches the user profile and group memberships in the **session** so views can use `$user->name`, `$user->email`, etc. without hitting the API on every request.
- Provides role checks against CodeSphere groups (`isMemberOfGroup`, `isOwnerOfGroup`, `canManageGroup`).
- Refreshes access tokens automatically when they expire.

What it does NOT do
-------------------

[](#what-it-does-not-do)

- It does not manage app-specific data (companies, teams, projects). Apps link their own data to CodeSphere groups via a `codesphere_group_id`column on their domain models, not via this package.
- It does not sync users into your local DB beyond a stub row keyed by `codesphere_id`. There is no `firstname`, `lastname`, `email`, or `avatar` column.

Install (local path repository)
-------------------------------

[](#install-local-path-repository)

In your app's `composer.json`:

```
{
    "repositories": [
        {
            "type": "path",
            "url": "packages/codesphere/oauth"
        }
    ],
    "require": {
        "code-sphere/oauth": "*"
    }
}
```

Then:

```
composer update code-sphere/oauth
php artisan vendor:publish --tag=codesphere-config
php artisan vendor:publish --tag=codesphere-migrations
php artisan migrate
```

Configuration
-------------

[](#configuration)

In `.env`:

```
CODESPHERE_ACCOUNTS_URL=https://account.code-sphere.de
CODESPHERE_CLIENT_ID=...
CODESPHERE_CLIENT_SECRET=...
CODESPHERE_REDIRECT_URI=https://your-app.example/auth/callback
CODESPHERE_APP_KEY=invoicesphere
CODESPHERE_ALLOWED_ACCOUNT_TYPES=business
CODESPHERE_HOME_ROUTE=dashboard

```

Use the trait on your User model
--------------------------------

[](#use-the-trait-on-your-user-model)

```
use CodeSphere\OAuth\Concerns\HasCodeSphereIdentity;

class User extends Authenticatable
{
    use HasCodeSphereIdentity;

    protected $fillable = [
        'codesphere_id',
        'access_token',
        'refresh_token',
        'token_expires_at',
        // ...your app-specific fields like current_company_id
    ];

    protected function casts(): array
    {
        return [
            'access_token' => 'encrypted',
            'refresh_token' => 'encrypted',
            'token_expires_at' => 'datetime',
        ];
    }
}
```

Listen for the login event
--------------------------

[](#listen-for-the-login-event)

The package fires `CodeSphere\OAuth\Events\CodeSphereLoggedIn` after a successful login. Listen for it to sync your app-specific records:

```
use CodeSphere\OAuth\Events\CodeSphereLoggedIn;

class SyncCompaniesAfterLogin
{
    public function handle(CodeSphereLoggedIn $event): void
    {
        foreach ($event->groups() as $group) {
            Company::firstOrCreate(
                ['codesphere_group_id' => $group['id']],
                ['name' => $group['name']],
            );
        }
    }
}
```

Routes provided
---------------

[](#routes-provided)

MethodURINamePurposeGET/auth/redirectcodesphere.redirectStart the OAuth flowGET/auth/callbackcodesphere.callbackOAuth callback handlerPOST/auth/logoutcodesphere.logoutLog out locallyGET/login (optional)loginRedirects to codesphere.redirectThe `login` route is registered automatically. Set `CODESPHERE_REGISTER_LOGIN_ROUTE=false` in `.env` if your app provides its own `login` route.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance61

Regular maintenance activity

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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/abc60fd4fb03424bcb741c1581dbf1b41e7ac4453f4e8c236e68e2c2bb93c68b?d=identicon)[c.ilgner](/maintainers/c.ilgner)

---

Top Contributors

[![Coho04](https://avatars.githubusercontent.com/u/73216313?v=4)](https://github.com/Coho04 "Coho04 (1 commits)")

### Embed Badge

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

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

###  Alternatives

[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)[firemultimedia/mautic-multi-captcha-bundle

This plugin brings Google's reCAPTCHA, hCaptcha, and Cloudflare Turnstile integration to mautic.

141.3k](/packages/firemultimedia-mautic-multi-captcha-bundle)

PHPackages © 2026

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