Lines
100.00%
10 / 10
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| readConfig | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| authenticateWorkstation | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | ||
| 8 | class OAuthService | |
| 9 | { | |
| 10 | protected Http $http; | |
| 11 | private string $configSecureToken; | |
| 12 | ||
| 13 | public function __construct(Http $http, string $configSecureToken) | |
| 14 | { | |
| 15 | $this->http = $http; | |
| 16 | $this->configSecureToken = $configSecureToken; | |
| 17 | } | |
| 18 | ||
| 19 | /** | |
| 20 | * Retrieve configuration with secure token | |
| 21 | * | |
| 22 | * @return Config | |
| 23 | */ | |
| 24 | public function readConfig(): Config | |
| 25 | { | |
| 26 | $entity = $this->http->readGetResult('/config/', [], $this->configSecureToken)->getEntity(); | |
| 27 | if (!$entity instanceof Config) { | |
| 28 | throw new \RuntimeException('Config lookup returned no config entity'); | |
| 29 | } | |
| 30 | return $entity; | |
| 31 | } | |
| 32 | ||
| 33 | /** | |
| 34 | * Authenticate OAuth user with workstation | |
| 35 | * | |
| 36 | * @param Useraccount $ownerInputData | |
| 37 | * @param string|null $state | |
| 38 | * @return mixed | |
| 39 | * @psalm-api | |
| 40 | */ | |
| 41 | public function authenticateWorkstation(Useraccount $ownerInputData, ?string $state = null) | |
| 42 | { | |
| 43 | $headers = []; | |
| 44 | if ($state !== null && $state !== '') { | |
| 45 | $headers['state'] = $state; | |
| 46 | } | |
| 47 | ||
| 48 | return $this->http->readPostResult('/workstation/oauth/', $ownerInputData, $headers)->getEntity(); | |
| 49 | } | |
| 50 | } |