flandera/open_id_connect_client_52

PHP 5.2 版本用于连接 OpenID 服务库

v0.25 2020-02-20 08:49 UTC

This package is auto-updated.

Last update: 2024-09-20 18:49:08 UTC


README

这是一个简单的库,允许应用程序通过基本的 OpenID Connect 流进行用户认证。这个库希望通过使其足够简单,以便于那些对 OpenID Connect 协议了解不多的开发者也能设置认证。

基于 https://github.com/jumbojett/OpenID-Connect-PHP,并针对 PHP 5.2 进行了重构。更多关于客户端功能的信息请参阅 Gitbub https://github.com/jumbojett/OpenID-Connect-PHP

要求

  1. PHP 5.2 或更高版本
  2. CURL 扩展
  3. JSON 扩展

安装

  1. 使用 composer 安装库
composer require flandera/openid-connect-php-52
  1. 包含 composer 自动加载器
require __DIR__ . '/vendor/autoload.php';

示例 1:基本客户端

$oidc = new JumbojettOpenIDConnectClient('https://id.provider.com', 'ClientIDHere', 'ClientSecretHere');
$oidc->setCertPath('/path/to/my.cert');

请参阅 [OpenID 规范](#) 了解可用的用户属性 [1]

示例 2:认证

$oidc = new JumbojettOpenIDConnectClient('https://id.provider.com',
                                'ClientIDHere',
                                'ClientSecretHere');
$oidc->providerConfigParam(array('token_endpoint'=>'https://id.provider.com/connect/token'));
$oidc->setRedirectURL('path/where_to_send/response');
$oidc->addScope('my_scope');
//Send authorization information i.e. username and password via form to auth endpoint
//get code and state from GET response of auth endpoint if success
$_SESSION['openid_connect_state'] = $_GET['state'];
$oidc->authenticate();
//if autentization is succesfull retrive token from response
$token = $oidc->getTokenResponse();
//get identity from response JWT payload
$identity = $oidc->getIdTokenPayload()->identity;
//Or use other workflow according to OpenID documentation

开发环境

在某些情况下,您可能需要在您的开发系统上禁用 SSL 安全性。注意:在生产系统上不推荐这样做。

$oidc->setVerifyHost(false);
$oidc->setVerifyPeer(false);