AbstractAuthentication::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of the PHP SDK library for the Superdesk Content API.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace Superdesk\ContentApiSdk\Api\Authentication;
16
17
use Superdesk\ContentApiSdk\Client\ClientInterface;
18
19
/**
20
 * Abstract class for accesstoken based authentication.
21
 */
22
abstract class AbstractAuthentication implements AuthenticationInterface
23
{
24
    /**
25
     * URI for requesting and refreshing tokens.
26
     */
27
    const AUTHENTICATION_URI = 'oauth/token';
28
29
    /**
30
     * HTTP Client for making authentication requests.
31
     *
32
     * @var ClientInterface
33
     */
34
    protected $client;
35
36
    /**
37
     * Access token for the API.
38
     *
39
     * @var string
40
     */
41
    protected $accessToken;
42
43
    /**
44
     * Client ID for the API.
45
     *
46
     * @var string
47
     */
48
    protected $clientId;
49
50
    /**
51
     * Base url for the api.
52
     *
53
     * @var string
54
     */
55
    protected $baseUrl;
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function __construct(ClientInterface $client)
61
    {
62
        $this->client = $client;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getAccessToken()
69
    {
70
        return $this->accessToken;
71
    }
72
73
    /**
74
     * Gets the value of clientId.
75
     *
76
     * @return string
77
     */
78
    public function getClientId()
79
    {
80
        return $this->clientId;
81
    }
82
83
    /**
84
     * Sets the value of clientId.
85
     *
86
     * @param string $clientId Value to set
87
     *
88
     * @return self
89
     */
90
    public function setClientId($clientId)
91
    {
92
        $this->clientId = $clientId;
93
94
        return $this;
95
    }
96
97
    /**
98
     * Gets the value of baseUrl.
99
     *
100
     * @return mixed
101
     */
102
    public function getBaseUrl()
103
    {
104
        return $this->baseUrl;
105
    }
106
107
    /**
108
     * Sets the value of baseUrl.
109
     *
110
     * @param mixed $baseUrl Value to set
111
     *
112
     * @return self
113
     */
114
    public function setBaseUrl($baseUrl)
115
    {
116
        $this->baseUrl = $baseUrl;
117
118
        return $this;
119
    }
120
121
    /**
122
     * Returns the url where authentication tokens can be retrieved.
123
     *
124
     * @return string
125
     */
126
    public function getAuthenticationUrl()
127
    {
128
        return sprintf('%s/%s', rtrim($this->getBaseUrl(), '/ '), self::AUTHENTICATION_URI);
129
    }
130
}
131