Passed
Push — master ( 132ee1...9612a9 )
by Alaa
01:36
created

Docusign::getDefaultHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sarhan\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Token\AccessToken;
7
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
8
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
9
use Psr\Http\Message\ResponseInterface;
10
11
class Docusign extends AbstractProvider
12
{
13
	use BearerAuthorizationTrait {
14
		getAuthorizationHeaders as getTokenBearerAuthorizationHeaders;
15
	}
16
	
17
	const URL_ROOT = 'https://account.docusign.com/oauth';
18
	const URL_ROOT_SANDBOX = 'https://account-d.docusign.com/oauth';
19
20
	const ENDPOINT_AUTHORIZTION = 'auth';
21
	const ENDPOINT_ACCESS_TOKEN = 'token';
22
	const ENDPOINT_RESOURCE_OWNER_DETAILS = 'userinfo';
23
24
	const SCOPE_SIGNATURE = 'signature';
25
	const SCOPE_EXTENDED = 'extended';
26
	const SCOPE_IMPERSONATION = 'impersonation';
27
	const SCOPES_DEFAULT = [
28
		self::SCOPE_SIGNATURE,
29
		self::SCOPE_EXTENDED
30
	];
31
	const SCOPES_SEPARATOR = ' ';
32
33
	protected $sandbox = false;
34
35
	/**
36
	 * @inheritDoc
37
	 */
38 2
	public function getBaseAuthorizationUrl() : string
39
	{
40 2
		return $this->getUrl(self::ENDPOINT_AUTHORIZTION);
41
	}
42
43
	/**
44
	 * @inheritDoc
45
	 */
46 1
	public function getBaseAccessTokenUrl(array $params) : string
47
	{
48 1
		return $this->getUrl(self::ENDPOINT_ACCESS_TOKEN);
49
	}
50
51
	/**
52
	 * @inheritDoc
53
	 */
54 2
	public function getResourceOwnerDetailsUrl(AccessToken $token) : string
55
	{
56 2
		return $this->getUrl(self::ENDPOINT_RESOURCE_OWNER_DETAILS);
57
	}
58
59 7
	public function getUrl($path)
60
	{
61 7
		return sprintf(
62 7
			'%s/%s',
63 7
			$this->sandbox ? self::URL_ROOT_SANDBOX : self::URL_ROOT,
64 7
			$path
65
		);
66
	}
67
68 1
	protected function getDefaultScopes()
69
	{
70 1
		return self::SCOPES_DEFAULT;
71
	}
72
73 3
	protected function checkResponse(ResponseInterface $response, $data)
74
	{
75 3
		if ($response->getStatusCode() >= 400) {
76 1
            throw new IdentityProviderException(
77 1
                $response->getReasonPhrase(),
78 1
                $response->getStatusCode(),
79 1
                $response
0 ignored issues
show
Bug introduced by
$response of type Psr\Http\Message\ResponseInterface is incompatible with the type array|string expected by parameter $response of League\OAuth2\Client\Pro...xception::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
                /** @scrutinizer ignore-type */ $response
Loading history...
80
            );
81
        }
82 2
	}
83
84 1
	protected function createResourceOwner(array $response, AccessToken $token)
85
	{
86 1
		return new DocusignUser($response, $token);
87
	}
88
89 1
	protected function getScopeSeparator()
90
    {
91 1
        return self::SCOPES_SEPARATOR;
92
    }
93
94 2
    protected function getDefaultHeaders()
95
    {
96 2
    	return ['Authorization' => 'Basic ' . $this->getBasicAuth()];
97
    }
98
99 2
	private function getBasicAuth() : string
100
	{
101 2
		return base64_encode(sprintf('%s:%s', $this->clientId, $this->clientSecret));
102
	}
103
}