PHPackages                             redmix0901/oauth2-client-sso - 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. redmix0901/oauth2-client-sso

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

redmix0901/oauth2-client-sso
============================

Package kết hợp với oauth2 client tạo đăng nhập single sign on

v1.8.2(3y ago)52.3k1[1 issues](https://github.com/redmix0901/oauth2-client-sso/issues)MITPHP

Since Oct 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/redmix0901/oauth2-client-sso)[ Packagist](https://packagist.org/packages/redmix0901/oauth2-client-sso)[ RSS](/packages/redmix0901-oauth2-client-sso/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (1)Versions (11)Used By (0)

Cài đặt
-------

[](#cài-đặt)

Cài đặt qua composer

```
composer require redmix0901/oauth2-client-sso
```

publish file config vào thư mục config

```
$ php artisan vendor:publish --tag=oauth2-sso-config
```

Sử dụng
-------

[](#sử-dụng)

middleware này sẽ luôn làm mới access token khi hết hạn.

```
Route::middleware('oauth2-sso')
```

Nếu bạn muốn redirect về trang Auth Server để đăng nhập nếu user chưa đăng thì thêm redirect phía sau.

```
Route::middleware('oauth2-sso:redirect')
```

Nếu muốn token được gắn trên cookie, để gọi xác thực api thì thêm cookie

```
Route::middleware('oauth2-sso:cookie')
```

Hoặc bạn có thể kết hợp cả 2:

```
Route::middleware('oauth2-sso:cookie,redirect')
```

Nếu cần xác thực Token của user từ Resource Server lên (Auth Server) id.todpev.vn thì dùng guard và config trong file config/auth.php như sau

```
'api' => [
    'driver' => 'sso-api',
    'provider' => 'users',
    'hash' => false,
]
```

Việc xác thực API sẽ có 2 trường hợp:

- Nếu không tách Resource Server và App Server ra làm 2 thì bạn có thể kiểm bằng cách thông qua cookie.

```
Route::middleware('oauth2-sso:cookie')
```

middleware này sẽ gắn token vào cookie và server sẽ kiểm tra token đó để xác thực.

- Trường hợp 2 là tách Resource Server và App Server: Bạn có xác thực bằng cookie với điều kiện là cả 2 cùng là Laravel, chung APP\_KEY và setup subdomain có thể share cookie cho nhau, và khai báo middleware như trên. Hoặc bạn phải gắn token vào header.

```
'Authorization' => 'Bearer ' . $token
```

-Trong trường hợp sử dụng Single page application, khi token trên cookie hết hạn bạn có thể gọi request /oauth2/issueToken để được cấp phát token mới. Nếu có lỗi, hết hạn hoặc bị logout thì sẽ trả về message sau:

```
[
    'error'   => true,
    'data'    => null,
    'message' => 'Unauthenticated.',
]
```

Chỉnh sửa config như sau:

```
'defaults' => [
    'guard' => 'oauth2',
    'passwords' => 'users',
],

'guards' => [
        ...
    'oauth2' => [
        'driver' => 'sso-session',
    ]
],
```

> defaults là không bắt buộc. Nếu không chỉnh sửa defaults thì bạn có thể dùng auth()-&gt;guard('oauth2')-&gt;user()

Nếu muốn lấy thông tin user từ request có thể dùng cách sau.

```
$request->user()
```

Nếu bạn chọn config mapingUser = true.
User sẽ được tự động map với user trong database cũa App Server.

Nếu Auth Server trả về 1 user mới thì nó sẽ tự động tạo 1 user với các trường mà Auth Server trả về và được map với fillable trong model User. Việc của bạn là update thông tin cho user đó trong event:

```
Redmix0901\Oauth2Sso\Events\UserSsoCreated::class
```

Có thể logout bằng link sau: /oauth2/logout hoặc bằng tên route sso.logout

Có thể login bằng phương thức get link sau: /oauth2/login hoặc bằng tên sso.login.authorization\_code

Login with email, password bằng phương thức post: /oauth2/login hoặc bằng tên sso.login.password\_grant

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

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

Recently: every ~78 days

Total

10

Last Release

1426d ago

### Community

Maintainers

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

---

Top Contributors

[![redmix0901](https://avatars.githubusercontent.com/u/36685246?v=4)](https://github.com/redmix0901 "redmix0901 (45 commits)")

---

Tags

clientlaravelSSOoauth2

### Embed Badge

![Health badge](/badges/redmix0901-oauth2-client-sso/health.svg)

```
[![Health](https://phpackages.com/badges/redmix0901-oauth2-client-sso/health.svg)](https://phpackages.com/packages/redmix0901-oauth2-client-sso)
```

###  Alternatives

[thenetworg/oauth2-azure

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

2509.6M48](/packages/thenetworg-oauth2-azure)[brenoroosevelt/oauth2-govbr

Cliente OAuth2 para Gov.br

2011.0k](/packages/brenoroosevelt-oauth2-govbr)[maicol07/laravel-oidc-client

OpenID Connect Client for Laravel

251.1k](/packages/maicol07-laravel-oidc-client)

PHPackages © 2026

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