crowdedlight/izettle-socialite

IZettle OAuth2 Provider for Laravel Socialite

v0.1 2017-08-25 01:05 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:24:37 UTC


README

安装和配置

安装 Laravel Socialite (见这里:https://github.com/laravel/socialite/blob/2.0/readme.md)

安装 IZettle 社交插件

composer require crowdedlight/izettle-socialite

将以下内容添加到您的 .env 文件中

IZETTLE_CLIENT_ID=
IZETTLE_CLIENT_SECRET=
IZETTLE_USERNAME=
IZETTLE_PASSWORD=
IZETTLE_REDIRECT=

密码授权

使用密码授权方法与 IZettle 进行私有集成时,请确保在 .env 文件中也填写了 IZETTLE_USERNAMEIZETTLE_PASSWORD 字段。IZETTLE_REDIRECT 在密码授权中不使用。

使用密码授权时,只需使用以下方法,因为它只需要与 API 进行一次交互。请记住,使用 Stateless,因为 API 不为这种交互使用 state

    /**
     * Gets the users AccessToken and Refreshtoken from the api.
     *
     *
     */
    public function AuthIzettle()
    {
        $user = Socialite::driver('izettle')->stateless()->user();
        //dd($user);
    }

Laravel <= 5.4

将以下内容添加到您的 config/app.php

crowdedlight\Socialite\IZettle\IZettleServiceProvider::class,

Laravel 5.5

服务提供者将自动发现。

使用方法

<?php

namespace App\Http\Controllers\Auth;

use Socialite;

class AuthController extends Controller
{
    /**
     * Redirect the user to the IZettle authentication page.
     *
     * @return Response
     */
    public function redirectToProvider()
    {
        return Socialite::driver('izettle')->redirect();
    }

    /**
     * Obtain the user information from IZettle.
     *
     * @return Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('izettle')->user();

        //dd($user);
    }
}

检索用户详情

一旦您有了用户实例,您还可以获取更多有关该用户的信息

$user = Socialite::driver('izettle')->user();

$token = $user->token;
$expiresIn = $user->expiresIn;
$user->getId();
$user->organization;