breadbutter / breadbutter-php
此包的最新版本(6.0.0)没有提供许可证信息。
BreadButter PHP API SDK
6.0.0
2022-08-17 19:32 UTC
This package is not auto-updated.
Last update: 2024-09-26 06:05:17 UTC
README
此库允许您将应用程序连接到Bread & Butter的认证过程。当用户认证成功时,用户将被重定向到您的应用程序。一旦您的应用程序获取到认证信息,您就可以执行创建用户或为该用户创建会话等操作。
安装
composer require breadbutter/breadbutter-php
API
有关完整的 DIY 快速入门指南 的更多信息,请访问 https://app.breadbutter.io/api/
用户在Bread & Butter处完成认证后,用户将被重定向到您Bread & Butter应用程序中定义的回调界面。以下是一个简单的界面示例,它接受Bread & Butter的请求并处理认证。
创建界面后,您需要在此处更新应用程序设置中的回调 URL,以指向此界面的URL:https://app.breadbutter.io/app/#/app-settings
处理认证请求
创建一个新的 BreadButterClient
实例
APP_ID
可在 https://app.breadbutter.io/app/#/app-settings 找到APP_SECRET
在 https://app.breadbutter.io/app/#/app-settings 进行配置
<?php use BreadButter\API\BreadButterClient; $breadButterClient = new BreadButterClient(array( 'app_id' => '{APP_ID}', 'app_secret' => '{APP_SECRET}', ));
从Bread & Butter服务器获取认证信息
您可以在以下位置找到详细的API响应: https://breadbutter.io/api/server-api/
<?php $authenticationToken = $_REQUEST['authentication_token']; $loginData = $breadButterClient->getAuthentication($authenticationToken); $body = $loginData['body']; $authData = $body['auth_data']; $email = $authData['email_address']; $firstName = $authData['first_name']; $lastName = $authData['last_name']; $profileImage = $authData['profile_image_url']; $destinationURL = $body['options']['destination_url']; //Use information above to create user in your system, create a session, etc
将用户重定向回您的网站
<?php header( "Location: $destinationURL" );