承接 cloudcogsio/oauth2-openid-connect-discovery 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

cloudcogsio/oauth2-openid-connect-discovery

Composer 安装命令:

composer require cloudcogsio/oauth2-openid-connect-discovery

包简介

This library extends the 'League OAuth2 Client' library to provide OpenID Connect Discovery support for supporting providers that expose a .well-known configuration endpoint.

README 文档

README

This library extends the League OAuth2 Client library to provide OpenID Connect Discovery support for providers that expose a .well-known configuration endpoint.

Installation

To install in an existing (or new) Oauth2 Client Provider library:

  1. Use composer:
composer require cloudcogsio/oauth2-openid-connect-discovery
  1. Change the client to extend \Cloudcogs\OAuth2\Client\OpenIDConnect\AbstractOIDCProvider instead of \League\OAuth2\Client\Provider\AbstractProvider

  2. Remove the following methods

getResourceOwnerDetailsUrl getBaseAuthorizationUrl getBaseAccessTokenUrl

Existing OAuth2 Client
class MyCustomClient extends \League\OAuth2\Client\Provider\AbstractProvider
{
    public function getResourceOwnerDetailsUrl(AccessToken $token)
    {
        ...
    }

    public function getBaseAuthorizationUrl()
    {
        ...
    }

    public function getBaseAccessTokenUrl(array $params)
    {
        ...
    }
}
Updated OAuth2 Client with OpenID Connect Discovery Support
class MyCustomClient extends \Cloudcogs\OAuth2\Client\OpenIDConnect\AbstractOIDCProvider
{
    ...
}

The existing client can now make use of the OIDC mechanisms implemented by this library.

See https://oauth2-client.thephpleague.com/providers/implementing for more information on implementing a new Client Provider.

Usage

Usage is the same as The League's OAuth client. Configuration options changes are required.

URL options can be removed

'urlAuthorize' 'urlAccessToken' 'urlResourceOwnerDetails'

Existing configuration
$provider = new MyCustomClient([
   'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
   'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
   'redirectUri'             => 'https://my.example.com/your-redirect-url/',
   'urlAuthorize'            => 'https://service.example.com/authorize',
   'urlAccessToken'          => 'https://service.example.com/token',
   'urlResourceOwnerDetails' => 'https://service.example.com/resource'
]);
New configuration
$provider = new MyCustomClient([
    'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
    'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
    'redirectUri'             => 'https://my.example.com/your-redirect-url/',
    'well_known_endpoint'     => 'https://identity.provider.com/.well-known/openid-configuration',
    'publickey_cache_provider'=> '',
]);
  • well_known_endpoint - The URL of the .well-known/openid-configuration endpoint of the IDP.
  • publickey_cache_provider - An empty string OR An instance of a \Laminas\Cache\Storage\Adapter\* storage adapter. See https://github.com/laminas/laminas-cache

Additional Notes and Usage

Your client provider instance will now have added functionality such as token introspection (if supported by your IDP) and the ability to obtain further configuration details from the provider.

Configuration data is accessed by proxying to the Discovery object from the client provider.

// Get the discovered configurations from the provider instance
$discovered = $provider->Discovery();

// Access standard OpenID Connect configuration via supported methods
$issuer = $discovered->getIssuer();
$supported_grants = $discovered->getGrantTypesSupported();
$authorization_endpoint = $discovered->getAuthorizationEndpoint();

// Or overloading for provider specific configuration
$custom_config = $discovered->custom_config;

// Cast to string to obtain the raw JSON discovery response
// All available properties for overloading can be seen in the JSON object.
$json_string = (string) $discovered;

IDP Public Key(s)

During endpoint discovery, the IDP public key(s) are retrieved and cached locally. This is needed to decode the access token (if required).

Caching of Public Keys

Caching of JWKs are handled by an instance of a \Laminas\Cache\Storage\Adapter\* storage adapter. If none is provided, \Laminas\Cache\Storage\Adapter\FileSystem is used.

You can provide your own instance of a \Laminas\Cache\Storage\Adapter\* to handle storage of the public keys.

Example
$storageAdapter = new \Laminas\Cache\Storage\Adapter\MongoDB($mdbOptions);

$provider = new MyCustomClient([
    'clientId'                => 'XXXXXX',    // The client ID assigned to you by the provider
    'clientSecret'            => 'XXXXXX',    // The client password assigned to you by the provider
    'redirectUri'             => 'https://my.example.com/your-redirect-url/',
    'well_known_endpoint'     => 'https://identity.provider.com/.well-known/openid-configuration',
    'publickey_cache_provider'=> $storageAdapter,
]);

Token Introspection

The AccessToken issued by the IDP can be decoded locally to obtain additional information.

// Decode the access token
$access_token = $AccessToken->getToken();
$data = $provider->introspectToken($access_token);

Token Introspection via the IDP (optional)

All tokens issued by the IDP (accessToken, refreshToken etc.) can be introspected using the token introspection endpoint if one is made available by the IDP.

// Decode the refresh token
$refresh_token = $AccessToken->getRefreshToken();
$data = $provider->introspectToken($refresh_token);

License

The MIT License (MIT). Please see License File for more information.

cloudcogsio/oauth2-openid-connect-discovery 适用场景与选型建议

cloudcogsio/oauth2-openid-connect-discovery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 186 次下载、GitHub Stars 达 5, 最近一次更新时间为 2021 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 cloudcogsio/oauth2-openid-connect-discovery 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 186
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 22
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-06