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
Github
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 Github extends AbstractOAuth2Provider
8{
9    /**
10     * Returns the Authorize URL
11     *
12     * @return string
13     */
14    protected function getAuthorizeUrl(): string
15    {
16        return 'https://github.com/login/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://github.com/login/oauth/access_token';
27    }
28
29    /**
30     * Returns the requested scope
31     *
32     * @return string|null
33     */
34    protected function getScope(): ?string
35    {
36        return null;
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://api.github.com/user', 'GET', null, [
49            'Authorization: Bearer ' . $accessToken['access_token'],
50        ]);
51
52        return new User(
53            $data['node_id'],
54            $data['login'],
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/Github.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(28,33,39,255)';
81    }
82}