kuainiu/laravel-kuainiu

API client wrapper for Laravel & Connect provider for Laravel Socialite

2.0.0 2019-10-23 04:33 UTC

This package is auto-updated.

Last update: 2024-04-23 14:45:14 UTC


README

Laravel-Kuainiu incorporates Kuainiu Connect and the Kuainiu API into your Laravel

Requirements

Installation

Add Laravel-Kuainiu to your composer file via the composer require command:

$ composer require kuainiu/laravel-kuainiu

Or add it to composer.json manually:

"require": {
    "kuainiu/laravel-kuainiu": "~1.0"
}

Configuration

To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish --provider="Kuainiu\KuainiuServiceProvider"

This will create a config/kuainiu.php file in your app that you can modify to set your configuration.

Kuainiu PAssport Connect with Laravel Socialite

If you intend on using Kuainiu Connect, update config/services.php by adding this to the array:

'kuainiu' => [
    'oauthServerDomain' => env('KUAINIU_OAUTH_DOMAIN'),
    'client_id'         => env('KUAINIU_CLIENT_ID', 'app_xxx'),
    'client_secret'     => env('KUAINIU_CLIENT_SECRET'),
    'redirect'          => env('KUAINIU_REDIRECT_URI'),
],

To make sure Laravel Socialite can actually find the Kuainiu driver, use the following code snippet and paste it in the boot() method from your AppServiceProvider.php.

Socialite::extend('kuainiu', function ($app) {
    $config = $app['config']['services.kuainiu'];

    return Socialite::buildProvider('Kuainiu\KuainiuConnectProvider', $config);
});

Usage

Here you can see an example of just how simple this package is to use.

Kuainiu API

$user = Kuainiu::api()->user()->create([
    "name"      => 'user_name_',
    "mobile" => "13800138000"
]);

$user = Kuainiu::createUser(['name'=>'name']);

if ($user->isCreated())
{
    echo "User Created.";
}

Kuainiu Passport Connect with Laravel Socialite

Route::get('login', function () {
    return Socialite::with('kuainiu')
        ->scopes('profiles.read profiles.write') // Additional permission: profiles.read profiles.write(the string need space separator)
        ->redirect();
});

Route::get('kuainiu/user/auth', function () {
    $user = Socialite::with('kuainiu')->stateless()->user();
    dd($user);
});

License

Copyright (c) 2018, Kuainiu Group