PHPackages                             xigemall/user-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. xigemall/user-sso

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

xigemall/user-sso
=================

xigemall user-sso

1.0.0(6y ago)18PHP

Since Jun 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/xigemall/user-sso)[ Packagist](https://packagist.org/packages/xigemall/user-sso)[ RSS](/packages/xigemall-user-sso/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

user-sso 三方登陆
=============

[](#user-sso-三方登陆)

1 远程包
-----

[](#1-远程包)

install
-------

[](#install)

`composer require xigemall/user-sso`

configure
---------

[](#configure)

`php artisan vendor:publish --provider="Xigemall\UserSso\UserSsoServiceProvider"`

add to your config/auth.php
---------------------------

[](#add-to-your-configauthphp)

```
'guards' => [
    'api' => [
        'driver' => 'sso',
        'provider' => 'sso',
    ],
],
'providers' => [
    'sso' => [
        'driver' => 'sso',
    ]
],
```

update to your config/sso.php
-----------------------------

[](#update-to-your-configssophp)

```
return [
    // 单点登录地址
    'url' => env('SSO_URL', 'http://localhost'),

    // client_id(客户端ID)
    'client_id' => env('CLIENT_ID', 1),

    // client_secret(客户端密钥)
    'client_secret' => env('CLIENT_SECRET', ''),

    // redirect_uri 授权时的重定向
    'redirect_uri'=>env('REDIRECT_URI','http://localhost/callback'),

    // 自增key (字段的名称) 默认id
    'increment_key' => 'id',

    // 密码字段 默认password
    'password' => 'password',

    // 获取当前用户接口地址
    'current_user_path' => '/api/current_user',
];
```

2 本地包
-----

[](#2-本地包)

### 1.项目根目录添加packages/xigemall目录

[](#1项目根目录添加packagesxigemall目录)

```
project
    app
    config
    packages //添加
        xigemall //添加
            user-sso //扩展包（github下载的该项目）
    composer.json

```

### 2.在项目（project）的composer.json添加repositories

[](#2在项目project的composerjson添加repositories)

```
"repositories": [
        {
            "type": "path",
            "url": "packages/xigemall/user-sso"
        }
    ],

```

3.install
---------

[](#3install)

`composer require xigemall/user-sso`

4.configure
-----------

[](#4configure)

`php artisan vendor:publish --provider="Xigemall\UserSso\UserSsoServiceProvider"`

add to your config/auth.php
---------------------------

[](#add-to-your-configauthphp-1)

```
'guards' => [
    'api' => [
        'driver' => 'sso',
        'provider' => 'sso',
    ],
],
'providers' => [
    'sso' => [
        'driver' => 'sso',
    ]
],
```

update to your config/sso.php
-----------------------------

[](#update-to-your-configssophp-1)

```
return [
         // 单点登录地址
            'url' => env('SSO_URL', 'http://localhost'),

            // client_id(客户端ID)
            'client_id' => env('CLIENT_ID', 1),

            // client_secret(客户端密钥)
            'client_secret' => env('CLIENT_SECRET', ''),

            // redirect_uri 授权时的重定向
            'redirect_uri'=>env('REDIRECT_URI','http://localhost/callback'),

            // 自增key (字段的名称) 默认id
            'increment_key' => 'id',

            // 密码字段 默认password
            'password' => 'password',

            // 获取当前用户接口地址
            'current_user_path' => '/api/current_user',
];
```

### 获取用户（前端请求headers添加Authorization）

[](#获取用户前端请求headers添加authorization)

```
    $response = $client->request('GET', '/api/user', [
        'headers' => [
            'Accept' => 'application/json',
            'Authorization' => 'Bearer '.$accessToken,
        ],
    ]);
```

### 三方登陆

[](#三方登陆)

```
授权登陆地址(获取code)
    /api/redirect

回调地址（获取accessToken）
    /api/access_token

```

### 重写登陆

[](#重写登陆)

```
class SsoController extends Controller
{
    use UserSso;
    /**
     * 请求令牌
     * 授权时的重定向
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function redirect()
    {
        $query = http_build_query([
            'client_id' => $this->clientId,
            'redirect_uri' => $this->redirectUri,
            'response_type' => 'code',
            'scope' => '',
        ]);
        return redirect($this->url . '/oauth/authorize?' . $query);
    }

    /**
     * 将授权码转换为访问令牌
     */
    public function callback(Request $request)
    {
        $code = $request->code;
        $url = $this->url.'/oauth/token';
        $data = [
            'grant_type' => 'authorization_code',
            'client_id' => $this->clientId,
            'client_secret' =>$this->clientSecret,
            'redirect_uri' => $this->redirectUri,
            'code' => $code,
        ];
        $response = UserSsoCurl::post($url, $data);

        return $response['access_token'];
    }
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2522d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/02f296630d7bc5c4230718e63a91cb15368798329d42e849a0ee1810897bc292?d=identicon)[xigemall](/maintainers/xigemall)

### Embed Badge

![Health badge](/badges/xigemall-user-sso/health.svg)

```
[![Health](https://phpackages.com/badges/xigemall-user-sso/health.svg)](https://phpackages.com/packages/xigemall-user-sso)
```

###  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.2M119](/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)
