-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9066415
Showing
7 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Created by https://www.gitignore.io | ||
|
||
### Composer ### | ||
composer.phar | ||
vendor/ | ||
|
||
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
# composer.lock | ||
|
||
|
||
### PhpStorm ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
|
||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
# if you remove the above rule, at least ignore the following: | ||
|
||
# User-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# .idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
# .idea/uiDesigner.xml | ||
|
||
# Gradle: | ||
# .idea/gradle.xml | ||
# .idea/libraries | ||
|
||
# Mongo Explorer plugin: | ||
# .idea/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: symfony |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Andrew Lau | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# OpenShift OAuth2 Provider for Laravel Socialite | ||
|
||
## Documentation | ||
|
||
This package makes use of the `SocialiteProviders` package located [here](http://socialiteproviders.github.io/). | ||
|
||
### Install the package | ||
|
||
```sh | ||
composer require andrewklau/socialite-openshift | ||
``` | ||
|
||
### Install the Service Provider | ||
|
||
* Remove `Laravel\Socialite\SocialiteServiceProvider` from your providers[] array in config\app.php if you have added it already. | ||
|
||
* Add `\SocialiteProviders\Manager\ServiceProvider::class` to your providers[] array in config\app.php. | ||
|
||
|
||
### Install the event listener | ||
|
||
* Add `SocialiteProviders\Manager\SocialiteWasCalled` event to your listen[] array in `<app_name>/Providers/EventServiceProvider`. | ||
|
||
|
||
* The listener that you add for this provider is `'Andrewklau\Socialite\OpenShift\OpenShiftkExtendSocialite@handle',`. | ||
|
||
For example: | ||
|
||
```php | ||
/** | ||
* The event handler mappings for the application. | ||
* | ||
* @var array | ||
*/ | ||
protected $listen = [ | ||
\SocialiteProviders\Manager\SocialiteWasCalled::class => [ | ||
// add your listeners (aka providers) here | ||
'Andrewklau\Socialite\OpenShift\OpenShiftExtendSocialite@handle', | ||
], | ||
]; | ||
``` | ||
|
||
### Environment variables | ||
|
||
If you add environment values to your `.env` as exactly shown below, you do not need to add an entry to the services array. | ||
|
||
#### Append to .env | ||
|
||
``` | ||
// other values above | ||
OPENSHIFT_URL=https://api.xyz.com | ||
OPENSHIFT_OAUTH_CLIENT_ID=yourkeyfortheservice | ||
OPENSHIFT_OAUTH_CLIENT_SECRET=yoursecretfortheservice | ||
``` | ||
|
||
#### Append to config/services.php | ||
|
||
You do not need to add this if you add the values to the `.env` exactly as shown above. The values below are provided as a convenience in the case that a developer is not able to use the .env method | ||
|
||
```php | ||
'openshift' => [ | ||
'client_id' => env('OPENSHIFT_OAUTH_CLIENT_ID'), | ||
'client_secret' => env('OPENSHIFT_OAUTH_CLIENT_SECRET'), | ||
'url' => env('OPENSHIFT_URL'), | ||
'redirect' => env('APP_URL').'/login/callback', | ||
], | ||
``` | ||
|
||
## Usage | ||
|
||
Redirect to OpenShift with the scopes you want to access: | ||
|
||
```php | ||
return Socialite::with('OpenShift')->scopes()->redirect(); | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "andrewklau/socialite-openshift", | ||
"description": "OpenShift OAuth2 Provider for Laravel Socialite", | ||
"license": "MIT", | ||
"authors": [{ | ||
"name": "Andrew Lau", | ||
"email": "[email protected]" | ||
}], | ||
"require": { | ||
"php": ">=5.5.9", | ||
"socialiteproviders/manager": "2.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Andrewklau\\Socialite\\OpenShift\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Andrewklau\Socialite\OpenShift; | ||
|
||
use SocialiteProviders\Manager\SocialiteWasCalled; | ||
|
||
class OpenShiftExtendSocialite | ||
{ | ||
/** | ||
* Execute the provider. | ||
*/ | ||
public function handle(SocialiteWasCalled $socialiteWasCalled) | ||
{ | ||
$socialiteWasCalled->extendSocialite( | ||
'openshift', __NAMESPACE__.'\Provider' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Andrewklau\Socialite\OpenShift; | ||
|
||
use Laravel\Socialite\Two\ProviderInterface; | ||
use SocialiteProviders\Manager\OAuth2\AbstractProvider; | ||
use SocialiteProviders\Manager\OAuth2\User; | ||
|
||
class Provider extends AbstractProvider implements ProviderInterface | ||
{ | ||
/** | ||
* Unique Provider Identifier. | ||
*/ | ||
const IDENTIFIER = 'OPENSHIFT'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $scopes = []; | ||
|
||
/** | ||
* Get the authentication URL for the provider. | ||
* | ||
* @param string $state | ||
* | ||
* @return string | ||
*/ | ||
protected function getAuthUrl($state) | ||
{ | ||
return $this->buildAuthUrlFromBase(config('services.openshift.url').'oauth/authorize', $state); | ||
} | ||
|
||
/** | ||
* Get the token URL for the provider. | ||
* | ||
* @return string | ||
*/ | ||
protected function getTokenUrl() | ||
{ | ||
return config('services.openshift.url').'oauth/token'; | ||
} | ||
|
||
/** | ||
* Get the raw user for the given access token. | ||
* | ||
* @param string $token | ||
* | ||
* @return array | ||
*/ | ||
protected function getUserByToken($token) | ||
{ | ||
$url = config('services.openshift.url').'oapi/v1/users/~'; | ||
|
||
$response = $this->getHttpClient()->get($url, [ | ||
'headers' => [ | ||
'Accept' => 'application/json', | ||
'Authorization' => 'Bearer '.$token, | ||
], | ||
]); | ||
|
||
return json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* Map the raw user array to a Socialite User instance. | ||
* | ||
* @param array $user | ||
* | ||
* @return \Laravel\Socialite\User | ||
*/ | ||
protected function mapUserToObject(array $user) | ||
{ | ||
return (new User())->setRaw($user)->map([ | ||
'id' => $user['metadata']['name'], | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getTokenFields($code) | ||
{ | ||
return array_merge(parent::getTokenFields($code), [ | ||
'grant_type' => 'authorization_code', | ||
]); | ||
} | ||
} |