From 8f90a2414ab03a1b4f10f036f0b534ab827064f2 Mon Sep 17 00:00:00 2001 From: Achmad Hadi Kurnia Date: Wed, 10 Jul 2024 20:10:06 +0700 Subject: [PATCH 1/2] chore(info): update README.md and command descriptions --- README.md | 110 +++++++++++++++++--- src/Commands/GenerateApimTokenCommand.php | 4 +- src/Commands/GenerateSsoTokenCommand.php | 4 +- src/Commands/GenerateTokenCommand.php | 4 +- src/Commands/GetRequestEndpointCommand.php | 4 +- src/Commands/PostRequestEndpointCommand.php | 4 +- 6 files changed, 106 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 1342c35..a6b4d99 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ Want to provide tangible support? Use the following platform to contribute to op - Patreon https://s.id/hadipatreon - Saweria https://s.id/hadisaweria -We highly appreciate you sending us a few cups of coffee to accompany us while writing code. Super thanks. +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. Don't hesitate to contact us at kanekescom@gmail.com for further information. +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 @@ -40,7 +40,75 @@ You can publish the config file with: php artisan vendor:publish --tag="siasn-api-config" ``` -Or, all installations can be completed with the install command: +This is the contents of the published config file: + +```php +// config/siasn-api.php + 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: ```bash php artisan siasn-api:install @@ -48,40 +116,54 @@ php artisan siasn-api:install ## Usage -Get APIM Token +### Token Generator + +Generate an APIM Token ```bash php artisan siasn:apim-token ``` -Forget APIM Token +Generate an SSO Token ```bash -php artisan siasn:forget-token +php artisan siasn:sso-token ``` -Get data from endpoint +Generate an APIM and SSO Token ```bash -php artisan siasn:get +php artisan siasn:token ``` -Post data to endpoint +You can add the `--fresh` option to always request a new token + +### Remove Token + +Remove an APIM and SSO Token ```bash -php artisan siasn:post +php artisan siasn:forget-token ``` -Get SSO Token +### Send Request + +Send a GET request to endpoint of SIASN API ```bash -php artisan siasn:sso-token +php artisan siasn:get {endpoint} ``` -Forget SSO Token +An example to get the referensi unor ```bash -php artisan siasn:token +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 + +```bash +php artisan siasn:post {endpoint} ``` ## Testing diff --git a/src/Commands/GenerateApimTokenCommand.php b/src/Commands/GenerateApimTokenCommand.php index 73cf1cf..5a7dfc0 100644 --- a/src/Commands/GenerateApimTokenCommand.php +++ b/src/Commands/GenerateApimTokenCommand.php @@ -8,9 +8,9 @@ class GenerateApimTokenCommand extends Command { protected $signature = 'siasn:apim-token - {--fresh : Always request new token}'; + {--fresh : Always request a new token}'; - protected $description = 'Generate APIM Token'; + protected $description = 'Generate an APIM Token'; public function handle(): int { diff --git a/src/Commands/GenerateSsoTokenCommand.php b/src/Commands/GenerateSsoTokenCommand.php index 275eac4..856aebd 100644 --- a/src/Commands/GenerateSsoTokenCommand.php +++ b/src/Commands/GenerateSsoTokenCommand.php @@ -8,9 +8,9 @@ class GenerateSsoTokenCommand extends Command { protected $signature = 'siasn:sso-token - {--fresh : Always request new token}'; + {--fresh : Always request a new token}'; - protected $description = 'Generate SSO Token'; + protected $description = 'Generate an SSO Token'; public function handle(): int { diff --git a/src/Commands/GenerateTokenCommand.php b/src/Commands/GenerateTokenCommand.php index 12c9c41..0f84f44 100644 --- a/src/Commands/GenerateTokenCommand.php +++ b/src/Commands/GenerateTokenCommand.php @@ -8,9 +8,9 @@ class GenerateTokenCommand extends Command { protected $signature = 'siasn:token - {--fresh : Always request new token}'; + {--fresh : Always request a new token}'; - protected $description = 'Generate APIM and SSO Token'; + protected $description = 'Generate an APIM and SSO Token'; public function handle(): int { diff --git a/src/Commands/GetRequestEndpointCommand.php b/src/Commands/GetRequestEndpointCommand.php index 8b53eec..76e398d 100644 --- a/src/Commands/GetRequestEndpointCommand.php +++ b/src/Commands/GetRequestEndpointCommand.php @@ -8,9 +8,9 @@ class GetRequestEndpointCommand extends Command { protected $signature = 'siasn:get - {endpoint : GET request to endpoint of SIASN API}'; + {endpoint : GET a request to endpoint of SIASN API}'; - protected $description = 'Send GET request to endpoint of SIASN API'; + protected $description = 'Send a GET request to the endpoint of SIASN API'; public function handle(): int { diff --git a/src/Commands/PostRequestEndpointCommand.php b/src/Commands/PostRequestEndpointCommand.php index 97b6d4f..b8ed3a4 100644 --- a/src/Commands/PostRequestEndpointCommand.php +++ b/src/Commands/PostRequestEndpointCommand.php @@ -8,9 +8,9 @@ class PostRequestEndpointCommand extends Command { protected $signature = 'siasn:post - {endpoint : POST request to endpoint of SIASN API}'; + {endpoint : POST a request to endpoint of SIASN API}'; - protected $description = 'Send POST request to endpoint of SIASN API'; + protected $description = 'Send a POST request to the endpoint of SIASN API'; public function handle(): int { From d40eccb2fef8d1142f22bf7c36d0e75276854778 Mon Sep 17 00:00:00 2001 From: Achmad Hadi Kurnia Date: Wed, 10 Jul 2024 20:24:27 +0700 Subject: [PATCH 2/2] chore(info): update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index a6b4d99..502b357 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,20 @@ Send a POST request to endpoint of SIASN API php artisan siasn:post {endpoint} ``` +### 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. + +```php +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. + +```php +Siasn::withSso()->get($endpoint, $params) +``` + ## Testing ```bash