定制 private-packagist/oidc-identities 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

private-packagist/oidc-identities

Composer 安装命令:

composer require private-packagist/oidc-identities

包简介

Create OIDC tokens on different platforms

README 文档

README

A PHP library that obtains OpenID Connect (OIDC) ID tokens from the CI/CD platform it is running on.

Modern CI/CD platforms can issue short-lived, signed OIDC tokens that prove the identity of the running workflow (which repository, which workflow, which branch, etc.). These tokens can be exchanged for credentials with a service that trusts the platform's OIDC provider — removing the need to store long-lived secrets in your CI configuration. This library handles the platform-specific work of detecting the environment and requesting such a token, then hands you back the parsed result.

Requirements

PHP >= 7.2.5

The library relies on HTTPlug / PSR-18 discovery, so you also need a PSR-18 HTTP client and PSR-17 factories available in your project (for example symfony/http-client and nyholm/psr7).

Install

Via Composer:

$ composer require private-packagist/oidc-identities

Supported platforms

Platform Detected via
GitHub Actions GITHUB_ACTIONS env var

The TokenGenerator tries each supported platform in turn and uses the first one that reports it is the current environment. When none of them match — for example when running locally — generate() returns null.

What is the TokenGenerator?

TokenGenerator is the main entry point of the library. You give it an $audience (the identifier of the service that will consume the token, e.g. Private Packagist), and it:

  1. Detects which supported platform the code is currently running on.
  2. Performs the platform-specific request to mint an OIDC ID token for that audience.
  3. Returns a Token value object containing the raw JWT together with its decoded header, payload and signature parts.

You would use it whenever your code runs inside a CI/CD pipeline and needs to prove its identity to an external service via OIDC, instead of relying on a stored secret. Because it abstracts away the per-platform details, the same call works on any supported platform without branching in your own code.

Usage

Initiate a TokenGenerator instance and call the generate method with $audience. The TokenGenerator will automatically try all supported platforms and return a Token for the first matching one, or null if the current environment is not supported.

use Http\Client\Common\HttpMethodsClient;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use PrivatePackagist\OIDC\Identities\TokenGenerator;
use Psr\Log\NullLogger;

// Configure a HttpMethodsClient instance
$oidcHttpClient = new HttpMethodsClient(
    Psr18ClientDiscovery::find(),
    Psr17FactoryDiscovery::findRequestFactory(),
    Psr17FactoryDiscovery::findStreamFactory(),
);

$tokenGenerator = new TokenGenerator(new NullLogger(), $oidcHttpClient);
$token = $tokenGenerator->generate($audience);

if ($token === null) {
    // Not running on a supported platform, or no OIDC token available.
    return;
}

// $token->token     — the raw JWT string
// $token->header    — decoded header
// $token->payload   — decoded payload
// $token->signature — the signature part

The constructor also accepts any PSR-3 LoggerInterface; pass a real logger instead of NullLogger to get debug output about platform detection and the token request.

Copyright and License

The library is licensed under the MIT License.

private-packagist/oidc-identities 适用场景与选型建议

private-packagist/oidc-identities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.01k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「OpenID Connect」 「oidc」 「identities」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 private-packagist/oidc-identities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 private-packagist/oidc-identities 我们能提供哪些服务?
定制开发 / 二次开发

基于 private-packagist/oidc-identities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 15.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 41
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-22