summaryrefslogtreecommitdiff
path: root/vendor/lusitanian/oauth/tests/Mocks/OAuth2/Service/Mock.php
blob: 508aea00a3f9666a7633de60f259156cedbf6787 (plain)
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
<?php

namespace OAuthTest\Mocks\OAuth2\Service;

use OAuth\OAuth2\Service\AbstractService;
use OAuth\Common\Http\Uri\Uri;
use OAuth\OAuth2\Token\StdOAuth2Token;

class Mock extends AbstractService
{
    const SCOPE_MOCK   = 'mock';
    const SCOPE_MOCK_2 = 'mock2';

    private $authorizationMethod = null;

    public function getAuthorizationEndpoint()
    {
        return new Uri('http://pieterhordijk.com/auth');
    }

    public function getAccessTokenEndpoint()
    {
        return new Uri('http://pieterhordijk.com/access');
    }

    protected function parseAccessTokenResponse($responseBody)
    {
        return new StdOAuth2Token();
    }

    // this allows us to set different auth methods for tests
    public function setAuthorizationMethod($method)
    {
        $this->authorizationMethod = $method;
    }

    /**
     * Returns a class constant from ServiceInterface defining the authorization method used for the API
     * Header is the sane default.
     *
     * @return int
     */
    protected function getAuthorizationMethod()
    {
        switch($this->authorizationMethod) {
            case 'querystring':
                return static::AUTHORIZATION_METHOD_QUERY_STRING;

            case 'querystring2':
                return static::AUTHORIZATION_METHOD_QUERY_STRING_V2;

            case 'bearer':
                return static::AUTHORIZATION_METHOD_HEADER_BEARER;
        }

        return parent::getAuthorizationMethod();
    }
}