Skip to content

Commit

Permalink
Add openshift_ca configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewklau committed Mar 30, 2017
1 parent 21624eb commit f319c5d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ If you add environment values to your `.env` as exactly shown below, you do not
```
// other values above
OPENSHIFT_URL=https://api.xyz.com
OPENSHIFT_CA=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
OPENSHIFT_OAUTH_CLIENT_ID=yourkeyfortheservice
OPENSHIFT_OAUTH_CLIENT_SECRET=yoursecretfortheservice
```
Expand All @@ -62,6 +63,7 @@ You do not need to add this if you add the values to the `.env` exactly as shown
'client_id' => env('OPENSHIFT_OAUTH_CLIENT_ID'),
'client_secret' => env('OPENSHIFT_OAUTH_CLIENT_SECRET'),
'url' => env('OPENSHIFT_URL'),
'ca' => env('OPENSHIFT_CA'),
'redirect' => env('APP_URL').'/login/callback',
],
```
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
}],
"require": {
"php": ">=5.5.9",
"socialiteproviders/manager": "3.*"
"socialiteproviders/manager": "3.*",
"guzzlehttp/guzzle": "~6.0"
},
"autoload": {
"psr-4": {
Expand Down
28 changes: 26 additions & 2 deletions src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Andrewklau\Socialite\OpenShift;

use GuzzleHttp\Client;
use Laravel\Socialite\Two\ProviderInterface;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;
Expand All @@ -13,11 +14,33 @@ class Provider extends AbstractProvider implements ProviderInterface
*/
const IDENTIFIER = 'OPENSHIFT';

/**
* The HTTP Client instance.
*
* @var \GuzzleHttp\Client
*/
protected $httpClient;

/**
* {@inheritdoc}
*/
protected $scopes = [];

/**
* Get a instance of the Guzzle HTTP client.
*
* @return \GuzzleHttp\Client
*/
protected function getHttpClient()
{
if (is_null($this->httpClient)) {
$this->httpClient = new Client([
'verify' => config('services.openshift.ca') ?: '',
]);
}
return $this->httpClient;
}

/**
* Get the authentication URL for the provider.
*
Expand Down Expand Up @@ -52,8 +75,9 @@ protected function getUserByToken($token)
$url = config('services.openshift.url').'oapi/v1/users/~';

$response = $this->getHttpClient()->get($url, [
'headers' => [
'Accept' => 'application/json',
'verify' => config('services.openshift.ca') ?: '',
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
],
]);
Expand Down

0 comments on commit f319c5d

Please sign in to comment.