Skip to content

kanekescom/laravel-siasn-api

Repository files navigation

Laravel SIASN API

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

SIASN REST API Client for Laravel. This library is the abstraction of SIASN API for access from applications written with Laravel PHP Framework.

Support us

Want to provide tangible support? Use the following platform to contribute to open-source software developers. Every contribution you make is a significant boost to continue building and enhancing technology that benefits everyone.

We highly appreciate you sending us a few cups of coffee to accompany us while writing code. Super, thanks.

Use pro version

We also offer a professional version. We're excited for you to try it out, as it allows us to consistently deliver high-quality software. Feel free to contact us at kanekescom@gmail.com or @achmadhadikurnia (maintainer) for further information.

  • Laravel SIASN Referensi Panel
  • Laravel SIASN SIMPEG Panel
  • SIMPEGDA App

Installation

You can install the package via composer:

composer require kanekescom/laravel-siasn-api

You can publish the config file with:

php artisan vendor:publish --tag="siasn-api-config"

This is the contents of the published config file:

// config/siasn-api.php
<?php

return [

    // Supported mode: "production", "training"
    'mode' => env('SIASN_MODE', 'training'),

    'apim' => [
        'production' => [
            'url' => 'https://apimws.bkn.go.id/oauth2/token',
            'grant_type' => 'client_credentials',
            'username' => env('SIASN_APIM_USERNAME'),
            'password' => env('SIASN_APIM_PASSWORD'),
        ],

        'training' => [
            'url' => 'https://training-apimws.bkn.go.id/oauth2/token',
            'grant_type' => 'client_credentials',
            'username' => env('TRAINING_SIASN_APIM_USERNAME'),
            'password' => env('TRAINING_SIASN_APIM_PASSWORD'),
        ],
    ],

    'sso' => [
        'production' => [
            'url' => 'https://sso-siasn.bkn.go.id/auth/realms/public-siasn/protocol/openid-connect/token',
            'grant_type' => 'password',
            'client_id' => env('SIASN_SSO_CLIENT_ID'),
            'username' => env('SIASN_SSO_USERNAME'),
            'password' => env('SIASN_SSO_PASSWORD'),
        ],

        'training' => [
            'url' => 'https://iam-siasn.bkn.go.id/auth/realms/public-siasn/protocol/openid-connect/token',
            'grant_type' => 'password',
            'client_id' => env('TRAINING_SIASN_SSO_CLIENT_ID'),
            'username' => env('TRAINING_SIASN_SSO_USERNAME'),
            'password' => env('TRAINING_SIASN_SSO_PASSWORD'),
        ],
    ],

    'const' => [
        'instansi_id' => env('SIASN_CONST_INSTANSI_ID'),
        'satuan_kerja_id' => env('SIASN_CONST_SATUAN_KERJA_ID'),
    ],

    'token_age' => [
        'apim' => (int) env('SIASN_APIM_TOKEN_AGE', 3600 - 60),
        'sso' => (int) env('SIASN_SSO_TOKEN_AGE', 43200 - 60),
    ],

    'debug' => (bool) env('SIASN_DEBUG', env('APP_DEBUG')),

    'enable_ssl_verification' => (bool) env('SIASN_ENABLE_SSL_VERIFICATION', true),

    'max_request_attempts' => (int) env('SIASN_REQUEST_ATTEMPTS', 3),

    'max_request_wait_attempts' => (int) env('SIASN_REQUEST_WAIT_ATTEMPTS', 30),

    'request_timeout' => (int) env('SIASN_REQUEST_TIMEOUT', 60),

];

Or, all installations can be completed with the installation command:

php artisan siasn-api:install

Usage

Token Generator

Generate an APIM Token

php artisan siasn:apim-token

Generate an SSO Token

php artisan siasn:sso-token

Generate an APIM and SSO Tokens

php artisan siasn:token

You can add the --fresh option to always request a new token

Remove Tokens

Remove an APIM and SSO Tokens

php artisan siasn:forget-token

Available Token Methods

Generate an APIM Token

Token::getNewApimToken(); // Always request a new APIM token
Token::getApimToken(); // Request a new APIM token

Token::getNewSsoToken(); // Always request a new SSO token
Token::getSsoToken(); // Request a new SSO token

Token::forget(); // Remove APIM and SSO Tokens

Send a Request

Using Command

Send a GET request to endpoint of SIASN API

php artisan siasn:get {endpoint}

An example to get the referensi unor

php artisan siasn:get https://apimws.bkn.go.id:8243/apisiasn/1.0/referensi/ref-unor

Send a POST request to endpoint of SIASN API

php artisan siasn:post {endpoint}

Send a Request Using Class

The Siasn class uses the Http class (Illuminate\Support\Facades\Http) from Laravel. So you can use it just like you would use that class.

Siasn::get($endpoint, $params)

We added the withSso() method for dual authentication purposes required by BKN. So you just need to add this method if needed, making it like the following.

Siasn::withSso()->get($endpoint, $params)

Testing

composer test

Our other cool packages

Need a package for other BKN's Web Service APIs? Consider installing our packages for seamless integration.

Referensi APIs

SIASNAPI-SIMPEG APIs

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.