PHPackages                             uptd-pelita/sso-broker-sdk - 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. uptd-pelita/sso-broker-sdk

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

uptd-pelita/sso-broker-sdk
==========================

SSO Broker SDK for Bali Province Applications

1.3(3mo ago)021MITPHPPHP ^7.4|^8.0

Since Feb 11Pushed 3mo agoCompare

[ Source](https://github.com/uptd-pelita/sso-broker-sdk)[ Packagist](https://packagist.org/packages/uptd-pelita/sso-broker-sdk)[ RSS](/packages/uptd-pelita-sso-broker-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

SSO Broker SDK for Bali Province Applications
=============================================

[](#sso-broker-sdk-for-bali-province-applications)

A Laravel package for integrating Single Sign-On (SSO) authentication with Bali Province SSO Server.

Requirements
------------

[](#requirements)

- PHP 7.4+ or PHP 8.0+
- Laravel 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, or 12.0
- GuzzleHTTP 6.0+ or 7.0+

Installation
------------

[](#installation)

### Via Composer (Private GitLab Repository)

[](#via-composer-private-gitlab-repository)

Since this is a private repository, you need to configure Composer to access it.

**Step 1:** Run composer update:

```
composer update uptd-pelita/sso-broker-sdk
```

### Using Tagged Versions (Recommended for Production)

[](#using-tagged-versions-recommended-for-production)

Once tags are created in the repository, use specific versions:

```
{
    "require": {
        "uptd-pelita/sso-broker-sdk": "^1.0"
    }
}
```

To create a version tag:

```
cd sso-baliprov-sdk
git tag -a v1.0.0 -m "Initial stable release"
git push origin v1.0.0
```

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

[](#configuration)

### 1. Publish Configuration

[](#1-publish-configuration)

```
php artisan vendor:publish --tag=sso-broker-config
```

### 2. Environment Variables

[](#2-environment-variables)

Add the following to your `.env` file:

```
SSO_DOMAIN=https://sso.baliprov.go.id
SSO_BROKER_CODE=your-broker-code
SSO_JWT_SECRET=your-jwt-secret
SSO_CALLBACK_ROUTE=/auth-data
SSO_REDIRECT_AFTER_LOGIN=/dashboard
SSO_REDIRECT_AFTER_LOGOUT=/
SSO_NOT_AUTHORIZED_ROUTE=not-authorized
```

### 3. Optional: Publish Routes

[](#3-optional-publish-routes)

If you want to customize routes:

```
php artisan vendor:publish --tag=sso-broker-routes
```

Then set `SSO_LOAD_DEFAULT_ROUTES=false` in your `.env` file.

Basic Usage
-----------

[](#basic-usage)

### Protecting Routes with Middleware

[](#protecting-routes-with-middleware)

```
// In routes/web.php

// Require SSO authentication
Route::middleware('sso.auth')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});

// Require specific role
Route::middleware('sso.role:admin')->group(function () {
    Route::get('/admin', [AdminController::class, 'index']);
});

// Require any of multiple roles
Route::middleware('sso.role:admin,editor,manager')->group(function () {
    Route::get('/manage', [ManageController::class, 'index']);
});
```

### Using the Facade

[](#using-the-facade)

```
use Baliprov\SSOBroker\Facades\SSOBroker;

// Check if authenticated
if (SSOBroker::isAuthenticated()) {
    // User is logged in
}

// Get user data
$user = SSOBroker::getUser();

// Get user roles
$roles = SSOBroker::getRoles();

// Check specific role
if (SSOBroker::hasRole('admin')) {
    // User has admin role
}

// Check any of multiple roles
if (SSOBroker::hasAnyRole(['admin', 'editor'])) {
    // User has at least one of these roles
}

// Get SSO user ID
$ssoUserId = SSOBroker::getSSOUserId();

// Set intended URL before redirecting to SSO
SSOBroker::setIntendedUrl('/dashboard');
```

### Manual Authentication in Controller

[](#manual-authentication-in-controller)

```
use Baliprov\SSOBroker\SSOBrokerManager;
use Illuminate\Http\Request;

class AuthController extends Controller
{
    protected SSOBrokerManager $sso;

    public function __construct(SSOBrokerManager $sso)
    {
        $this->sso = $sso;
    }

    public function login(Request $request)
    {
        return $this->sso->authenticate($request);
    }

    public function logout(Request $request)
    {
        return $this->sso->logoutAndRedirect($request);
    }
}
```

Extending the SDK
-----------------

[](#extending-the-sdk)

### Custom Controller

[](#custom-controller)

Create a custom controller that extends the base:

```
