Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
OAuthService
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 readConfig
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 authenticateWorkstation
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace BO\Zmsclient;
4
5use BO\Zmsentities\Config;
6use BO\Zmsentities\Useraccount;
7
8class 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}