-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE4oProvider.php
70 lines (56 loc) · 1.92 KB
/
E4oProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types = 1);
namespace App\OAuth\Provider;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Provider\GenericResourceOwner;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use Psr\Http\Message\ResponseInterface;
class E4oProvider extends AbstractProvider
{
use BearerAuthorizationTrait;
protected string $serverUrl;
protected string $serverAuthorizePath;
protected string $serverTokenPath;
protected string $serverProfilePath;
public function getBaseAuthorizationUrl(): string
{
return "$this->serverUrl/$this->serverAuthorizePath";
}
public function getBaseAccessTokenUrl(array $params): string
{
return "$this->serverUrl/$this->serverTokenPath";
}
protected function getDefaultScopes(): array
{
return [
'user:read:profile',
];
}
public function getResourceOwnerDetailsUrl(AccessToken $token): string
{
return "$this->serverUrl/$this->serverProfilePath";
}
protected function checkResponse(ResponseInterface $response, $data): void
{
}
protected function createResourceOwner(array $response, AccessToken $token): ResourceOwnerInterface
{
return new GenericResourceOwner(
$response,
$response['email']
?? throw new \InvalidArgumentException('Response missing user e-mail')
);
}
protected function getAllowedClientOptions(array $options): array
{
$options = parent::getAllowedClientOptions($options);
$data = parse_url($this->serverUrl);
if (str_ends_with($data['host'], 'localhost')) {
// THIS MIGHT BE DANGEROUS! Use for testing with self-signed certificates only.
$options[] = 'verify';
}
return $options;
}
}