theodorejb/saml-utils

简化Light Saml使用的实用工具

v1.2.0 2024-07-22 21:16 UTC

This package is auto-updated.

Last update: 2024-09-22 21:39:39 UTC


README

本软件包在Light Saml的基础上提供了一些有用的实用工具,以简化常见任务。

通过Composer安装

composer require theodorejb/saml-utils

与元数据一起工作

SamlMetadata类简化了从身份提供者元数据中获取数据。调用SamlMetadata::fromXml($xml)从实体描述符XML字符串创建一个实例。

可以通过只读属性$entityDescriptor访问底层的EntityDescriptor对象。

SamlMetadata实现了以下方法

getIdpCertificate()

返回身份提供者证书的X509Certificate实例。

getIdpSsoService()

返回身份提供者定义的用于接收SAML请求以启动单点登录的Redirect或POST SingleSignOnService

getIdpLogoutService()

返回身份提供者定义的Redirect或POST SingleLogoutService

实用方法

SamlUtils类实现了以下静态实用方法

getRequestFromGlobals(): MessageContext

从全局GET/POST数据返回SAML请求或响应的对象。

getMessageHttpResponse(SamlMessage $message, string $bindingType): Response

返回一个Symfony\Component\HttpFoundation\Response实例,用于发送SAML消息。

validateSignature(SamlMessage $message, X509Certificate $certificate): void

如果消息签名缺失或与证书验证失败,则抛出异常。

getSubjectNameId(SamlResponse $response): string

返回由身份提供者断言的用户身份。

getFirstAttributeStatement(SamlResponse $response): AttributeStatement|null

如果存在,则返回第一个断言属性声明。

getAttributeStatementValue(AttributeStatement $statement, string $name): string

返回指定属性名的断言属性值。如果属性不存在,则抛出异常。

getResponseAttributeValue(SamlResponse $response, string $name): string

getAttributeStatementValue()相同,但可以直接从SamlResponse而不是AttributeStatement中使用。