authwave/php-client

该软件包最新版本(v0.3.0)没有可用的许可信息。

PHP 客户端库,用于在您的应用程序中实现 Authwave

v0.3.0 2020-05-18 22:12 UTC

README

Authwave 是一个开源的 Identity-as-a-Service 产品,可以自托管。使用 Authwave 允许您的应用程序提供具有良好用户体验和安全的认证,而无需您自己编写任何认证代码。

要使用此存储库,您的应用程序必须注册以获取客户端密钥(见以下示例)。这可以通过https://www.authwave.com或从您自己的Authwave Provider实例完成,如果您是自托管的话。

基本用法

以下 PHP 代码可以显示一个登录按钮,点击后变为登出按钮,并显示已登录用户的问候语。

<?php
use Authwave\Authenticator;
require __DIR__ . "/vendor/autoload.php";

// This constant can be loaded from your application's configuration
// or environment variables. It is created in the remote Authwave provider.
define("CLIENT_KEY", "1234567890abcdef");

// Construct the Authenticator class as soon as possible, as this handles the
// Authentication steps passed via the query string from the remote provider.
$auth = new Authenticator(
	CLIENT_KEY,
	$_SERVER["REQUEST_URI"]
);

// Handle authentication login/logout action via the querystring:
if(isset($_GET["login"])) {
// This will redirect the user agent to the auth uri, which is a location on the 
// remote provider. The remote provider will in turn redirect the user agent
// back to the return URI (set as 3rd parameter of Authenticator's constructor),
// at which point the user will be considered authenticated.
	$auth->login();
}
elseif(isset($_GET["logout"])) {
	$auth->logout();
}

// Authentication is handled by Authwave, so you can trust "isLoggedIn"
// as a mechanism for protecting your sensitive information.
if($auth->isLoggedIn()) {
	echo <<<HTML
		<p>You are logged in as <strong>{$auth->getEmail()}</strong></p>
		<p><a href="?logout">Log out</a></p>
	HTML;
}
else {
	echo <<<HTML
		<p>You are not logged in!</p>
		<p><a href="?login">Log in</a></p>
	HTML;
}