PHPackages                             novay/smrpas - 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. novay/smrpas

ActiveProject

novay/smrpas
============

Samarinda Digital ID integration for Laravel.

1.0.0(10mo ago)06MITPHP

Since Jul 16Pushed 10mo agoCompare

[ Source](https://github.com/novay/smrpas)[ Packagist](https://packagist.org/packages/novay/smrpas)[ Docs](https://github.com/novay/smrpas)[ RSS](/packages/novay-smrpas/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

SMR-PAS (Samarinda Digital ID)
==============================

[](#smr-pas-samarinda-digital-id)

SMR-PAS is a Laravel package designed to integrate the Samarinda Digital ID single sign-on (SSO) system into your Laravel applications. It leverages Laravel Passport for OAuth-based authentication, allowing seamless and secure user authentication with the Samarinda Digital ID platform. This package simplifies the process of connecting your application to the SMR-PAS server, enabling users to log in using their Samarinda Digital ID credentials.

### Requirements

[](#requirements)

To use the SMR-PAS package, ensure your application meets the following requirements:

- PHP: 7.4 or higher
- Laravel: 8.x or higher

### How it works?

[](#how-it-works)

The SMR-PAS package integrates your application with the Samarinda Digital ID OAuth server. Here's how it works:

1. **OAuth Authorization:** The package redirects users to the SMR-PAS OAuth server (`https://smrpas.samarindakota.go.id`) for authentication.
2. **User Consent:** Users are prompted to log in and consent to share their identity details with your application (configurable via `OAUTH_PROMPT`).
3. **Token Exchange:** Upon successful authentication, the SMR-PAS server redirects the user back to your application with an authorization code, which is exchanged for an access token.
4. **User Authentication:** The access token is used to authenticate the user and retrieve their profile information, allowing seamless SSO integration.
5. **Redirect:** After successful login, users are redirected to a configurable home route (e.g., `/dashboard`).

The package handles the OAuth flow, state validation, and token management, ensuring secure and efficient integration with the Samarinda Digital ID system.

### Installation

[](#installation)

[![IMAGE ALT TEXT](https://camo.githubusercontent.com/a73ecf0b8f5b1a3f492c671ce6ebc1f272ad432cfa5744ec130c939578be871b/687474703a2f2f696d672e796f75747562652e636f6d2f76692f434148335259474e7431512f302e6a7067)](http://www.youtube.com/watch?v=CAH3RYGNt1Q "Video Title")

Follow these steps to install and configure the SMR-PAS package in your Laravel application:

#### 1. Install the Package

[](#1-install-the-package)

Install the package using Composer:

```
composer require novay/smrpas
```

The package uses Laravel's auto-discovery feature, so the `Novay\Smrpas\SmrpasServiceProvider` is automatically registered in your application.

#### 2. Publish Vendor Assets

[](#2-publish-vendor-assets)

Publish the package's configuration files, migrations, and other assets:

```
php artisan vendor:publish --provider="Novay\Smrpas\SmrpasServiceProvider"
```

This will copy the package’s configuration file (`config/smrpas.php`) and migrations to your application.

#### 3. Run Migrations

[](#3-run-migrations)

The package includes database migrations to set up OAuth-related tables. We just need to target only the package’s migrations, run the migrations using:

```
php artisan migrate --path=vendor/novay/smrpas/src/Database/migrations/2023_09_26_100536_create_oauths_table.php
```

#### 4. Configure Environment Variables

[](#4-configure-environment-variables)

Add the following environment variables to your `.env` file to configure the SMR-PAS OAuth integration:

```
OAUTH_SERVER_ID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
OAUTH_SERVER_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
OAUTH_SERVER_REDIRECT_URI=https://yourdomain.com/oauth/callback
OAUTH_SERVER_URI=https://smrpas.samarindakota.go.id
OAUTH_PROMPT=consent
OAUTH_HOME=/dashboard
```

**Variable Descriptions:**

- `OAUTH_SERVER_ID`: The client ID issued by the SMR-PAS OAuth server for your application.
- `OAUTH_SERVER_SECRET`: The plain-text client secret issued by the SMR-PAS OAuth server (do not use the hashed version).
- `OAUTH_SERVER_REDIRECT_URI`: The callback URL where the SMR-PAS server redirects users after authentication (must match the URI registered in the SMR-PAS server).
- `OAUTH_SERVER_URI`: The base URL of the SMR-PAS OAuth server (e.g., `https://smrpas.samarindakota.go.id`).
- `OAUTH_PROMPT`: The OAuth prompt behavior. Options are:
    - `none`: No prompt; assumes the user is already authenticated.
    - `consent`: Prompts the user to consent to sharing their data.
    - `login`: Forces the user to log in, even if they have an active session.
- `OAUTH_HOME`: The route users are redirected to after successful authentication (e.g., `/dashboard`).

#### 5. Use Trait in User Model

[](#5-use-trait-in-user-model)

To enable OAuth token management for users in your application, add the `TokenTrait` provided by the SMR-PAS package to your `User` model. This trait provides methods to handle OAuth tokens seamlessly. Update your `User` model (typically located at `app/Models/User.php`):

```
