serato/sso-auth-request

该软件包已被弃用,不再维护。没有建议的替代软件包。
该软件包最新版本(v2.0.0)没有可用的许可信息。

处理SSO授权请求的库

v2.0.0 2023-03-16 02:57 UTC

This package is auto-updated.

Last update: 2024-07-11 22:40:51 UTC


README

一个用于处理对Serato SSO服务的Web应用程序授权请求的PHP库。

SSO授权请求生命周期

Web应用程序的SSO授权请求生命周期如下

  1. Web应用程序使用\Serato\SsoRequest\AuthRequest类创建一个新的授权请求
    • Web应用程序提供了一个返回URL,SSO服务在登录过程后会重定向到该URL。
    • 提供了一个存储机制,在重定向到SSO网站时持久化授权请求的详细信息。
  2. 新的授权请求返回一个ID。
  3. 浏览器通过在state URI参数中提供授权请求ID,重定向到SSO网站。
  4. 浏览器从SSO服务返回到Web应用程序,SSO服务提供了state参数以及code参数。
  5. Web应用程序通过提供通过state URI参数传递的授权ID,创建一个\Serato\SsoRequest\AuthRequest实例。
  6. Web应用程序通过使用\Serato\SsoRequest\AuthRequest实例和code URI参数中提供的值,从SSO服务接收访问和刷新令牌。

在SSO重定向期间存储授权请求

定义了一个Serato\SsoRequest\AuthRequestStorageInterface存储接口,用于在SSO重定向期间存储授权请求。

AuthRequestStorageInterface实现存储了在授权生命周期中使用的应用程序ID、请求ID和重定向URL值,以及时间戳和指示授权过程完成的方式。

Serato\SsoRequest\AuthRequestDynamoDbStorage类提供了一个使用DynamoDB表作为存储机制的Serato\SsoRequest\AuthRequestStorageInterface实现。

在请求生命周期中使用\Serato\SsoRequest\AuthRequest

注意:所有示例都使用Serato\SsoRequest\AuthRequestDynamoDbStorage作为存储机制。

创建一个新的授权请求(如上所述第1步)

use Serato\SsoRequest\AuthRequest;
use Serato\SsoRequest\AuthRequestDynamoDbStorage;

// Application ID of the web application
$appId = 'my-app-id';

// URI that the SSO service will redirect to after sign on
$redirectUri = 'http://my.server.com/uri/after/soo';

// Create a new AuthRequest
// Assumes `$awsSdk` is a correctly configured `Aws\Sdk` instance
$authRequest = AuthRequest::create(
    $appId,
    $redirectUri,
    new AuthRequestDynamoDbStorage($awsSdk)
);

// Get the new request ID
$requestId = $authRequest->getId();

 // Construct the SSO service URI to redirect the browser to
$ssoStartUri = 'http://sso.service.com?' . http_build_query([
    'app_id' => $appId,
    'state' => $authRequest->getId(),
    'redirect_uri' => $redirectUri
]);

## Redirect the browser to the SSO service

在登录后返回Web应用程序后创建一个AuthRequest实例(如上所述第5步),并使用它从SSO服务获取刷新和访问令牌(如上所述第6步)

use Serato\SsoRequest\AuthRequest;
use Serato\SsoRequest\AuthRequestDynamoDbStorage;

// Application ID of the web application
$appId = 'my-app-id';

// Create a new AuthRequest
// Assumes `$awsSdk` is a correctly configured `Aws\Sdk` instance
// Assumes `$requestId` is obtained from the `state` URI parameter
$authRequest = AuthRequest::createFromStorage(
    $requestId,
    $appId,
    new AuthRequestDynamoDbStorage($awsSdk)
);

// Now fetch refresh and access tokens from the SSO service
// Assumes `$swsSdk` a configured `Serato\SwsSdk\Sdk` instance;
// Assumes `$code` is obtained from the `code` URI parameter
$result = $authRequest->getTokens($swsSdk, $code);

## $result is a `Serato\SwsSdk\Result` instance
## Use array access syntax to access result data