mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
38 lines
985 B
PHP
38 lines
985 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Unity\Services;
|
|
|
|
use Config;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class GetAccessToken
|
|
{
|
|
private $unityConfig;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->unityConfig = Config::get('unity');
|
|
}
|
|
|
|
public function execute(){
|
|
|
|
//TODO: Cache access token base on expiry for login version
|
|
|
|
$accesToken='';
|
|
if($this->unityConfig['default_auth']=='login'){
|
|
$loginDetails = $this->unityConfig['auth']['login'];
|
|
$response = Http::post($this->unityConfig['url'].$this->unityConfig['endpoint']['login'], [
|
|
'email' => $loginDetails['username'],
|
|
'password' => $loginDetails['password'],
|
|
])->object();
|
|
$accesToken = $response->access_token;
|
|
}else{
|
|
$accesToken = $this->unityConfig['auth']['api_key']['key'];
|
|
}
|
|
|
|
//TODO: Throw error if access token not available
|
|
|
|
return $accesToken;
|
|
}
|
|
}
|