Skip to content

Commit e6dc16f

Browse files
committed
Merge pull request #9 from cbdr/make-path-in-config
make token request path configurable
2 parents 6d1647d + 07faf7c commit e6dc16f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/CareerBuilder/OAuth2/Flows/Flow.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ abstract class Flow
4242
protected $headers;
4343
/** @var array */
4444
protected $body;
45+
/** @var string */
46+
private $tokenRequestPath;
4547

4648
/**
4749
* @param array $configs
@@ -50,18 +52,34 @@ abstract class Flow
5052
*/
5153
protected function __construct(array $configs, ClientInterface $client = null, LoggerInterface $logger = null)
5254
{
55+
$configs = array_merge($this->getDefaultConfig(), $configs);
5356
$this->setCredentials($configs);
5457
$this->setDefaults();
5558

56-
57-
if (isset($configs['auth_in_header']) && $configs['auth_in_header']) {
59+
if ($configs['auth_in_header']) {
5860
$this->headers['Authorization'] = $this->getAuthHeader();
5961
}
6062

6163
$this->logger = $logger ?: new NullLogger();
6264
$this->client = $client ?: new Client();
6365
$this->client->setBaseUrl($configs['base_url']);
6466
$this->client->addSubscriber(new LogPlugin(new PsrLogAdapter($this->logger)));
67+
$this->tokenRequestPath = $configs['token_request_path'];
68+
}
69+
70+
/**
71+
* @return array
72+
*/
73+
private function getDefaultConfig()
74+
{
75+
return array(
76+
'client_id' => '',
77+
'client_secret' => '',
78+
'shared_secret' => '',
79+
'base_url' => 'https://api.careerbuilder.com',
80+
'token_request_path' => '/oauth/token',
81+
'auth_in_header' => false
82+
);
6583
}
6684

6785
/**
@@ -110,7 +128,7 @@ public function getToken(AccessToken $token = null)
110128
$this->buildBody();
111129
}
112130

113-
$request = $this->client->post('/oauth/token', $this->headers, $this->body);
131+
$request = $this->client->post($this->tokenRequestPath, $this->headers, $this->body);
114132
$response = $request->send();
115133
$data = $response->json();
116134

@@ -128,4 +146,4 @@ protected function getJWT($claims)
128146
{
129147
return JWT::encode($claims, $this->sharedSecret, 'HS512');
130148
}
131-
}
149+
}

0 commit comments

Comments
 (0)