GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( eac42d...55bb68 )
by François
02:33
created

WebfingerModule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU Lesser General Public License as published by
6
 *  the Free Software Foundation, either version 3 of the License, or
7
 *  (at your option) any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU Lesser General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU Lesser General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
namespace fkooman\RemoteStorage;
19
20
use fkooman\RemoteStorage\Http\Exception\HttpException;
21
use fkooman\RemoteStorage\Http\Request;
22
use fkooman\RemoteStorage\Http\Response;
23
24
class WebfingerModule
25
{
26
    /** @var string */
27
    private $serverMode;
28
29
    /**
30
     * @param string $serverMode
31
     */
32
    public function __construct($serverMode)
33
    {
34
        $this->serverMode = $serverMode;
35
    }
36
37
    public function getWebfinger(Request $request)
38
    {
39
        $resource = $request->getQueryParameter('resource');
40
        if (null === $resource) {
41
            throw new HttpException('resource parameter missing', 400);
42
        }
43
        if (0 !== strpos($resource, 'acct:')) {
44
            throw new HttpException('unsupported resource type', 400);
45
        }
46
        $userAddress = substr($resource, 5);
47
        $atPos = strpos($userAddress, '@');
48
        if (false === $atPos) {
49
            throw new HttpException('invalid user address', 400);
50
        }
51
        $user = substr($userAddress, 0, $atPos);
52
53
        $webFingerData = [
54
            'links' => [
55
                [
56
                    'href' => sprintf('%s%s', $request->getRootUri(), $user),
57
                    'properties' => [
58
                        'http://remotestorage.io/spec/version' => 'draft-dejong-remotestorage-05',
59
                        'http://remotestorage.io/spec/web-authoring' => null,
60
                        'http://tools.ietf.org/html/rfc6749#section-4.2' => sprintf('%s_oauth/authorize?login_hint=%s', $request->getRootUri(), $user),
61
                        'http://tools.ietf.org/html/rfc6750#section-2.3' => 'true',
62
                        'http://tools.ietf.org/html/rfc7233' => 'development' !== $this->serverMode ? 'GET' : null,
63
                    ],
64
                    'rel' => 'http://tools.ietf.org/id/draft-dejong-remotestorage',
65
                ],
66
                // legacy -03 WebFinger response
67
                [
68
                    'href' => sprintf('%s%s', $request->getRootUri(), $user),
69
                    'properties' => [
70
                        'http://remotestorage.io/spec/version' => 'draft-dejong-remotestorage-03',
71
                        'http://tools.ietf.org/html/rfc2616#section-14.16' => 'development' !== $this->serverMode ? 'GET' : false,
72
                        'http://tools.ietf.org/html/rfc6749#section-4.2' => sprintf('%s_oauth/authorize?login_hint=%s', $request->getRootUri(), $user),
73
                        'http://tools.ietf.org/html/rfc6750#section-2.3' => true,
74
                    ],
75
                    'rel' => 'remotestorage',
76
                ],
77
            ],
78
        ];
79
80
        $response = new Response(200, 'application/jrd+json');
81
        $response->addHeader('Access-Control-Allow-Origin', '*');
82
        $response->setBody(
83
            json_encode($webFingerData)
84
        );
85
86
        return $response;
87
    }
88
}
89