-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitLab.php
51 lines (42 loc) · 1.43 KB
/
GitLab.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
<?php
/**
* Class GitLab
*
* @created 29.07.2019
* @author smiley <smiley@chillerlan.net>
* @copyright 2019 smiley
* @license MIT
*/
declare(strict_types=1);
namespace chillerlan\OAuth\Providers;
use chillerlan\OAuth\Core\{
AuthenticatedUser, ClientCredentials, ClientCredentialsTrait, CSRFToken, OAuth2Provider, TokenRefresh, UserInfo,
};
/**
* GitLab OAuth2
*
* @link https://docs.gitlab.com/ee/api/oauth2.html
*/
class GitLab extends OAuth2Provider implements ClientCredentials, CSRFToken, TokenRefresh, UserInfo{
use ClientCredentialsTrait;
public const IDENTIFIER = 'GITLAB';
protected string $authorizationURL = 'https://gitlab.com/oauth/authorize';
protected string $accessTokenURL = 'https://gitlab.com/oauth/token';
protected string $apiURL = 'https://gitlab.com/api';
protected string|null $applicationURL = 'https://gitlab.com/profile/applications';
protected string|null $apiDocs = 'https://docs.gitlab.com/ee/api/rest/';
/** @codeCoverageIgnore */
public function me():AuthenticatedUser{
$json = $this->getMeResponseData('/v4/user');
$userdata = [
'data' => (array)$json,
'avatar' => $json['avatar_url'],
'displayName' => $json['name'],
'email' => $json['email'],
'handle' => $json['username'],
'id' => $json['id'],
'url' => $json['web_url'],
];
return new AuthenticatedUser($userdata);
}
}