theodorejb / saml-utils
简化Light Saml使用的实用工具
v1.2.0
2024-07-22 21:16 UTC
Requires
- php: >=8.1
- litesaml/lightsaml: ^4.1
Requires (Dev)
- phpunit/phpunit: ^10.4
- psalm/plugin-phpunit: ^0.18.4
- vimeo/psalm: ^5.15
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
中使用。