friendship ended with social-app. php is my new best friend
1<?php
2/**
3 * Class GitLab
4 *
5 * @created 29.07.2019
6 * @author smiley <smiley@chillerlan.net>
7 * @copyright 2019 smiley
8 * @license MIT
9 */
10declare(strict_types=1);
11
12namespace chillerlan\OAuth\Providers;
13
14use chillerlan\OAuth\Core\{
15 AuthenticatedUser, ClientCredentials, ClientCredentialsTrait, CSRFToken, OAuth2Provider, TokenRefresh, UserInfo,
16};
17
18/**
19 * GitLab OAuth2
20 *
21 * @link https://docs.gitlab.com/ee/api/oauth2.html
22 */
23class GitLab extends OAuth2Provider implements ClientCredentials, CSRFToken, TokenRefresh, UserInfo{
24 use ClientCredentialsTrait;
25
26 public const IDENTIFIER = 'GITLAB';
27
28 protected string $authorizationURL = 'https://gitlab.com/oauth/authorize';
29 protected string $accessTokenURL = 'https://gitlab.com/oauth/token';
30 protected string $apiURL = 'https://gitlab.com/api';
31 protected string|null $applicationURL = 'https://gitlab.com/profile/applications';
32 protected string|null $apiDocs = 'https://docs.gitlab.com/ee/api/rest/';
33
34 /** @codeCoverageIgnore */
35 public function me():AuthenticatedUser{
36 $json = $this->getMeResponseData('/v4/user');
37
38 $userdata = [
39 'data' => (array)$json,
40 'avatar' => $json['avatar_url'],
41 'displayName' => $json['name'],
42 'email' => $json['email'],
43 'handle' => $json['username'],
44 'id' => $json['id'],
45 'url' => $json['web_url'],
46 ];
47
48 return new AuthenticatedUser($userdata);
49 }
50
51}