mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-29 17:34:25 +00:00
Assign contract obligations at Unity
This commit is contained in:
@@ -7,31 +7,39 @@ use Illuminate\Support\Facades\Http;
|
||||
|
||||
class GetAccessToken
|
||||
{
|
||||
private $unityConfig;
|
||||
private $getAccessTokenEndpoint;
|
||||
|
||||
private $username;
|
||||
|
||||
private $password;
|
||||
|
||||
private $apiKey;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->unityConfig = Config::get('unity');
|
||||
$this->getAccessTokenEndpoint = Config::get('unity.url').Config::get('unity.endpoint.login');
|
||||
$this->username = Config::get('unity.auth.login.username');
|
||||
$this->password = Config::get('unity.auth.login.password');
|
||||
$this->apiKey = Config::get('unity.auth.api_key.key');
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
|
||||
//TODO: Cache access token base on expiry for login version
|
||||
//Note: Cache access token base on expiry from login not ideal as token may gets overwritten if user login Unity dashboard
|
||||
|
||||
$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'],
|
||||
$accessToken='';
|
||||
if(empty($this->apiKey)){
|
||||
$response = Http::post($this->getAccessTokenEndpoint, [
|
||||
'email' => $this->username,
|
||||
'password' => $this->password ,
|
||||
])->object();
|
||||
$accesToken = $response->access_token;
|
||||
$accessToken = $response->access_token;
|
||||
}else{
|
||||
$accesToken = $this->unityConfig['auth']['api_key']['key'];
|
||||
$accessToken = $this->apiKey;
|
||||
}
|
||||
|
||||
//TODO: Throw error if access token not available
|
||||
|
||||
return $accesToken;
|
||||
return $accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user