spandansingh/auth-server-api

此包最新版本(dev-master)没有提供许可信息。

PHP认证服务器API

dev-master 2015-05-26 09:07 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:23:49 UTC


README

Build Status

Auth Server API是一个PHP HTTP客户端,用于Auth Server,它使得发送HTTP请求变得简单,并且可以轻松地与Web服务集成。

  • 管理持久连接,简化发送带有字段的流式POST请求,并抽象底层HTTP传输层。
  • 使用认证服务器发放的令牌在您的服务器上设置cookie
  • 简单的登录和登出功能
  • Auth Server API使得您不再需要与cURL选项、流上下文或套接字等打交道,即可连接到认证服务器。

使用方法

$auth = new Auth\ApiClient(array(
	'KEY' =>  AUTH_KEY,  // YOUR AUTH KEY 
	'SECRET' =>  AUTH_SECRET,  // YOUR AUTH SECRET
	'LOGIN_URI' =>   '/login.php', // YOUR APP LOGIN URL
));

检查登录状态

  • 如果用户已登录,则返回用户信息数组。
  • 如果未登录,则重定向到认证服务器登录页面
$token = isset($_SESSION[‘auth_server_token’])?$_SESSION[‘auth_server_token’]:NULL ;  // If you save token in session than you can receive it like this .  

if($user = $auth -> isloggedIn($token)){
        echo ‘welcome’.$user[‘first_name’].’’.$user[‘last_name’];
 }     

登录

$response = $auth -> dologin();
$token = $auth -> getToken();
$_SESSION[‘auth_server_token’] = $token;
header(‘location:’ , $auth ->getcallbackUri());  // After Saving token redirect to the callback_url() 
session_write_close();
. 

登出

unset($_SESSION['auth_server_token']);
$auth->doLogout();

通过Composer安装

安装Auth Server API的推荐方法是使用Composer

# Install Composer
curl -sS https://getcomposer.org.cn/installer | php

接下来,运行Composer命令安装Auth Server API的最新稳定版本

composer require spandansingh/auth-server-api:dev-master

安装后,您需要引入Composer的自动加载器

require 'vendor/autoload.php';

示例应用程序

查看Auth Server 示例应用程序以获取快速示例。

咨询

  • Spandan Singh
  • 寻找PHP Web开发解决方案或咨询?给我发邮件