summaryrefslogtreecommitdiff
path: root/app/Core/OAuth2.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-07-16 20:35:56 -0400
committerFrederic Guillot <fred@kanboard.net>2015-07-16 20:35:56 -0400
commitede1f1d9b0c06a05845f4125d59c97c29b6d9842 (patch)
tree2fc9f21c586501d43440dace17e71bfb40618bfc /app/Core/OAuth2.php
parent12036aa21f4308aca4d816864b357f9627a0f437 (diff)
Refactoring of Github authentication (oauth url change)
Diffstat (limited to 'app/Core/OAuth2.php')
-rw-r--r--app/Core/OAuth2.php49
1 files changed, 47 insertions, 2 deletions
diff --git a/app/Core/OAuth2.php b/app/Core/OAuth2.php
index a0b33e31..a7d04f33 100644
--- a/app/Core/OAuth2.php
+++ b/app/Core/OAuth2.php
@@ -19,6 +19,18 @@ class OAuth2 extends Base
private $tokenType;
private $accessToken;
+ /**
+ * Create OAuth2 service
+ *
+ * @access public
+ * @param string $clientId
+ * @param string $secret
+ * @param string $callbackUrl
+ * @param string $authUrl
+ * @param string $tokenUrl
+ * @param array $scopes
+ * @return OAuth2
+ */
public function createService($clientId, $secret, $callbackUrl, $authUrl, $tokenUrl, array $scopes)
{
$this->clientId = $clientId;
@@ -31,6 +43,12 @@ class OAuth2 extends Base
return $this;
}
+ /**
+ * Get authorization url
+ *
+ * @access public
+ * @return string
+ */
public function getAuthorizationUrl()
{
$params = array(
@@ -43,15 +61,28 @@ class OAuth2 extends Base
return $this->authUrl.'?'.http_build_query($params);
}
+ /**
+ * Get authorization header
+ *
+ * @access public
+ * @return string
+ */
public function getAuthorizationHeader()
{
- if ($this->tokenType === 'Bearer') {
+ if (strtolower($this->tokenType) === 'bearer') {
return 'Authorization: Bearer '.$this->accessToken;
}
return '';
}
+ /**
+ * Get access token
+ *
+ * @access public
+ * @param string $code
+ * @return string
+ */
public function getAccessToken($code)
{
if (empty($this->accessToken) && ! empty($code)) {
@@ -64,7 +95,7 @@ class OAuth2 extends Base
'grant_type' => 'authorization_code',
);
- $response = json_decode($this->httpClient->postForm($this->tokenUrl, $params), true);
+ $response = json_decode($this->httpClient->postForm($this->tokenUrl, $params, array('Accept: application/json')), true);
$this->tokenType = isset($response['token_type']) ? $response['token_type'] : '';
$this->accessToken = isset($response['access_token']) ? $response['access_token'] : '';
@@ -72,4 +103,18 @@ class OAuth2 extends Base
return $this->accessToken;
}
+
+ /**
+ * Set access token
+ *
+ * @access public
+ * @param string $token
+ * @param string $type
+ * @return string
+ */
+ public function setAccessToken($token, $type = 'bearer')
+ {
+ $this->accessToken = $token;
+ $this->tokenType = $type;
+ }
}