PHPackages                             lifewind/laravel-sso-client - 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. lifewind/laravel-sso-client

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

lifewind/laravel-sso-client
===========================

Laravel SSO client for LifeWind authentication

v1.0.0(3mo ago)00MITPHPPHP ^8.1

Since Feb 9Pushed 1mo agoCompare

[ Source](https://github.com/LifeWind-Ltda/laravel-sso-client)[ Packagist](https://packagist.org/packages/lifewind/laravel-sso-client)[ RSS](/packages/lifewind-laravel-sso-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (2)Used By (0)

LifeWind Laravel SSO Client
===========================

[](#lifewind-laravel-sso-client)

**API-only SSO authentication for Laravel backends.**

This package provides secure JWT-based authentication endpoints for validating OAuth tokens from frontend applications.

🌟 Features
----------

[](#-features)

- ✅ **API-Only Architecture**: Pure JSON endpoints, no redirects
- ✅ **JWT Authentication**: Secure token-based authentication
- ✅ **OAuth 2.0 Flow**: Industry standard OAuth implementation
- ✅ **User Management**: Automatic user creation and updates
- ✅ **CORS Ready**: Cross-domain frontend support
- ✅ **Frontend Agnostic**: Works with Vue, React, Angular, or any frontend

📋 Prerequisites: Register Your App in LifeWind Core
---------------------------------------------------

[](#-prerequisites-register-your-app-in-lifewind-core)

Before installing this package, you need an OAuth client registered in LifeWind Core:

1. **Login** to the LifeWind Core admin panel at `https://lifewind-core.test/admin` (or your production URL)
2. Navigate to **OAuth Clients** → **Create Client**
3. Fill in:
    - **Name**: Your app name (e.g. "Atlas")
    - **Redirect URI**: Your frontend callback URL (e.g. `https://your-app.com/sso/callback`)
    - **Grant Type**: Authorization Code
4. After creation, copy the **Client ID** and **Client Secret** — you'll need these for your `.env`

> **Tip**: For local development, use `http://localhost:3001/sso/callback` as the redirect URI (adjust port to match your frontend dev server).

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Installation

[](#1-installation)

```
composer require lifewind/laravel-sso-client
```

### 2. Configuration

[](#2-configuration)

Publish configuration and run migrations:

```
php artisan vendor:publish --provider="LifeWind\SSO\SSOServiceProvider"
php artisan migrate
```

### 3. Environment Setup

[](#3-environment-setup)

```
# LifeWind SSO Configuration
LIFEWIND_SSO_BASE_URL=https://lifewind-core.your-domain.com
LIFEWIND_SSO_CLIENT_ID=your_oauth_client_id
LIFEWIND_SSO_CLIENT_SECRET=your_oauth_client_secret
LIFEWIND_SSO_REDIRECT_URI=https://your-frontend.com/sso/callback
LIFEWIND_SSO_CREATE_USERS=true
LIFEWIND_SSO_UPDATE_USERS=true

# JWT Configuration
LIFEWIND_SSO_JWT_SECRET=your-256-bit-secret-key
LIFEWIND_SSO_JWT_EXPIRY=86400
```

### 4. CORS Configuration

[](#4-cors-configuration)

Update `config/cors.php`:

```
return [
    'paths' => ['api/*', 'sso/*'],
    'allowed_origins' => ['https://your-frontend.com'],
    'allowed_headers' => ['*'],
    'allowed_methods' => ['*'],
    'supports_credentials' => false, // JWT in Authorization header
];
```

📡 API Endpoints
---------------

[](#-api-endpoints)

The package automatically registers these endpoints:

MethodEndpointDescription`POST``/sso/validate`Validate OAuth code → return JWT + user`GET``/sso/user`Get authenticated user (Bearer token)`POST``/sso/refresh`Refresh JWT token### POST /sso/validate

[](#post-ssovalidate)

Exchange OAuth authorization code for JWT token.

**Request:**

```
{
  "code": "oauth_authorization_code_from_callback",
  "state": "oauth_state_parameter",
  "redirect_uri": "https://your-frontend.com/sso/callback"
}
```

**Success Response (200):**

```
{
  "success": true,
  "user": {
    "id": 1,
    "email": "user@example.com",
    "name": "John Doe",
    "lifewind_uuid": "550e8400-e29b-41d4-a716-446655440000"
  },
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  "expires_in": 86400
}
```

**Error Response (400):**

```
{
  "success": false,
  "error": "Token validation failed: Invalid authorization code"
}
```

### GET /sso/user

[](#get-ssouser)

Get current authenticated user information.

**Headers:**

```
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Accept: application/json

```

**Success Response (200):**

```
{
  "authenticated": true,
  "local_user": {
    "id": 1,
    "email": "user@example.com",
    "name": "John Doe",
    "lifewind_uuid": "550e8400-e29b-41d4-a716-446655440000"
  },
  "authenticated_via": "jwt",
  "token_expiry": "2024-01-15T14:30:00.000Z"
}
```

**Error Response (401):**

```
{
  "error": "Invalid or expired authentication token",
  "authenticated": false
}
```

### POST /sso/refresh

[](#post-ssorefresh)

Refresh an existing JWT token.

**Headers:**

```
Authorization: Bearer current_jwt_token
Accept: application/json

```

**Success Response (200):**

```
{
  "success": true,
  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  "expires_in": 86400,
  "token_expiry": "2024-01-16T14:30:00.000Z"
}
```

🔒 Protecting Routes
-------------------

[](#-protecting-routes)

Use the built-in middleware to protect your API routes:

```
// routes/api.php
Route::middleware(['lifewind.auth'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
    Route::apiResource('projects', ProjectController::class);
    Route::get('/profile', [UserController::class, 'profile']);
});
```

🛠️ Using in Controllers
-----------------------

[](#️-using-in-controllers)

Access the authenticated user in your controllers:

```
