-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitlab.php
87 lines (71 loc) · 2.25 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace dokuwiki\plugin\oauthgitlab;
use dokuwiki\plugin\oauth\Service\AbstractOAuth2Base;
use OAuth\Common\Http\Uri\Uri;
use OAuth\Common\Consumer\CredentialsInterface;
use OAuth\Common\Http\Client\ClientInterface;
use OAuth\Common\Storage\TokenStorageInterface;
use OAuth\Common\Http\Uri\UriInterface;
/**
* Custom Service for GitLab oAuth
*/
class Gitlab extends AbstractOAuth2Base
{
public function __construct(
CredentialsInterface $credentials,
ClientInterface $httpClient,
TokenStorageInterface $storage,
$scopes = array(),
UriInterface $baseApiUri = null
) {
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
$hlp = plugin_load('helper', 'oauthgitlab');
$this->baseurl = rtrim($hlp->getConf('url'), '/');
if (null === $baseApiUri) {
$this->baseApiUri = new Uri($this->baseurl.'/api/v4/');
}
}
/** @inheritdoc */
public function getAuthorizationEndpoint()
{
$plugin = plugin_load('helper', 'oauthgitlab');
return new Uri($plugin->getConf('url').'/oauth/authorize');
}
/** @inheritdoc */
public function getAccessTokenEndpoint()
{
$plugin = plugin_load('helper', 'oauthgitlab');
return new Uri($plugin->getConf('url').'/oauth/token');
}
/**
* @inheritdoc
*/
protected function getAuthorizationMethod()
{
return static::AUTHORIZATION_METHOD_HEADER_BEARER;
}
/**
* Logout from GitLab
*
* @return void
* @throws \OAuth\Common\Exception\Exception
*/
public function logout()
{
global $ID;
$plugin = plugin_load('helper', 'oauthgitlab');
$token = $this->getStorage()->retrieveAccessToken($this->service());
$parameters = [
'client_id' => $this->credentials->getConsumerId(),
'client_secret' => $this->credentials->getConsumerSecret(),
'token' => $token
];
$this->httpClient->retrieveResponse(
new Uri($plugin->getConf('url').'/oauth/revoke'),
$parameters,
$this->getExtraOAuthHeaders()
);
$parameters = array();
send_redirect(wl($ID, $parameters, true, '&'));
}
}