PHP code example of her-cat / colourlife-oauth2
1. Go to this page and download the library: Download her-cat/colourlife-oauth2 library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
her-cat / colourlife-oauth2 example snippets
PHP >= 7.0
erCat\ColourlifeOauth2\ColourlifeOAuth2Provider;
use Overtrue\Socialite\SocialiteManager;
$config = [
'colourlife' => [
'client_id' => 'your-ice-application-id',
'client_secret' => 'your-ice-secret',
'redirect' => 'http://localhost/callback.php',
'environment' => 'prod',
],
];
$socialite = new SocialiteManager($config);
$socialite->extend('colourlife', function ($config) use ($socialite) {
$config = $config['colourlife'] ?? [];
/** @var ColourlifeOAuth2Provider $provider */
$provider = $socialite->buildProvider(ColourlifeOAuth2Provider::class, $config);
return $provider->environment($config['environment'] ?? 'prod');
});
$response = $socialite->driver('colourlife')->redirect();
$response->send();
erCat\ColourlifeOauth2\ColourlifeOAuth2Provider;
use Overtrue\Socialite\SocialiteManager;
$config = [
'colourlife' => [
'client_id' => 'your-ice-application-id',
'client_secret' => 'your-ice-secret',
'redirect' => 'http://localhost/callback.php',
'environment' => 'prod',
],
];
$socialite = new SocialiteManager($config);
$socialite->extend('colourlife', function ($config) use ($socialite) {
$config = $config['colourlife'] ?? [];
/** @var ColourlifeOAuth2Provider $provider */
$provider = $socialite->buildProvider(ColourlifeOAuth2Provider::class, $config);
return $provider->environment($config['environment'] ?? 'prod');
});
$user = $socialite->driver('colourlife')->user();
$user->getId(); // xxxxxxxxxx
$user->getName(); // her-cat
$user->getProviderName(); // colourlife
$user->getAttribute('mobile'); // 18500000001
'providers' => [
// Other service providers...
HerCat\ColourlifeOAuth2\ServiceProvider::class,
],
'aliases' => [
// Other aliases...
'ColourlifeOAuth2' => HerCat\ColourlifeOAuth2\Facades\ColourlifeOAuth2::class,
],
return [
//...
'colourlife' => [
'client_id' => 'your-ice-application-id',
'client_secret' => 'your-ice-secret',
'redirect' => config('app.url').'/oauth/colourlife/callback',
'environment' => 'prod', // OAuth 服务环境,dev: 测试,prod:正式
],
//...
];
namespace App\Http\Controllers;
use HerCat\ColourlifeOAuth2\Facades\ColourlifeOAuth2;
class AuthController extends Controller
{
public function redirect()
{
return ColourlifeOAuth2::redirect();
}
public function handleCallback()
{
$user = ColourlifeOAuth2::user();
print_r($user->getName());
}
}
Route::get('/oauth/colourlife', 'AuthController@redirect');
Route::get('/oauth/colourlife/callback', 'AuthController@handleCallback');