Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Gitlab
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 getAuthorizeUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAccessTokenUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getScope
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUserProfile
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getLogoSource
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getThemeColor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Miniframe\SocialLogin\Provider;
4
5use Miniframe\SocialLogin\Model\User;
6
7class Gitlab extends AbstractOAuth2Provider
8{
9    /**
10     * Returns the Authorize URL
11     *
12     * @return string
13     */
14    protected function getAuthorizeUrl(): string
15    {
16        return 'https://gitlab.com/oauth/authorize';
17    }
18
19    /**
20     * Returns the Access Token URL
21     *
22     * @return string
23     */
24    protected function getAccessTokenUrl(): string
25    {
26        return 'https://gitlab.com/oauth/token';
27    }
28
29    /**
30     * Returns the requested scope
31     *
32     * @return string|null
33     */
34    protected function getScope(): ?string
35    {
36        return 'read_user';
37    }
38
39    /**
40     * Returns the user profile
41     *
42     * @param array $accessToken The access token.
43     *
44     * @return User
45     */
46    protected function getUserProfile(array $accessToken): User
47    {
48        $data = $this->curlRequest('https://gitlab.com/api/v4/user', 'GET', null, [
49            'Authorization: Bearer ' . $accessToken['access_token'],
50        ]);
51
52        return new User(
53            $data['id'],
54            $data['username'],
55            $data['name'],
56            $data['avatar_url'],
57            static::class,
58            ['accessToken' => $accessToken, 'userData' => $data]
59        );
60    }
61
62    /**
63     * Returns the image source for the logo of this provider.
64     *
65     * @return string
66     */
67    public static function getLogoSource(): string
68    {
69        return 'data:image/svg+xml;base64,'
70            . base64_encode(file_get_contents(__DIR__ . '/../../templates/logos/Gitlab.svg'));
71    }
72
73    /**
74     * Returns the theme color for this provider.
75     *
76     * @return string
77     */
78    public static function getThemeColor(): string
79    {
80        return 'rgba(51,46,107,255)';
81    }
82}