Passed
Pull Request — master (#8)
by
unknown
23:25 queued 09:34
created

getRevokeAccessTokenMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
1
<?php
2
3
namespace Bogstag\OAuth2\Client\Provider;
4
5
use GuzzleHttp\Exception\BadResponseException;
6
use League\OAuth2\Client\Provider\AbstractProvider;
7
use League\OAuth2\Client\Token\AccessTokenInterface;
8
use Psr\Http\Message\RequestInterface;
9
10
abstract class AbstractExtendedProvider extends AbstractProvider
11
{
12
    /**
13
     * Returns the base URL for revoking an access token.
14
     *
15
     * Eg. https://oauth.service.com/revoke
16
     *
17
     * @return string
18
     */
19
    abstract public function getBaseRevokeAccessTokenUrl();
20
21
    /**
22
     * Revokes an access token.
23
     *
24
     * @param AccessTokenInterface $token
25
     * @throws BadResponseException
26
     * @return void
27
     */
28
    public function revokeAccessToken(AccessTokenInterface $token)
29
    {
30
        $params = [
31
            'client_id'     => $this->clientId,
32
            'client_secret' => $this->clientSecret,
33
            'token'         => $token->getToken(),
34
        ];
35
36
        $request = $this->getRevokeAccessTokenRequest($params);
37
38
        $this->getResponse($request);
39
    }
40
41
    /**
42
     * Returns a prepared request for revoking an access token.
43
     *
44
     * @param array $params Post body parameters
45
     * @return RequestInterface
46
     */
47
    protected function getRevokeAccessTokenRequest(array $params)
48
    {
49
        $method = $this->getRevokeAccessTokenMethod();
50
        $url    = $this->getBaseRevokeAccessTokenUrl();
51
52
        return $this->getRequest($method, $url, $params);
53
    }
54
55
    /**
56
     * Returns the method to use when revoking an access token.
57
     *
58
     * @return string HTTP method
59
     */
60
    protected function getRevokeAccessTokenMethod()
61
    {
62
        return self::METHOD_POST;
63
    }
64
}
65