groupepsih/oauth2-prosanteconnect

Pro Sante Connect / ANS OAuth 2.0 客户端提供商,用于 PHP League OAuth2-Client

1.0.2 2023-01-17 15:17 UTC

This package is auto-updated.

Last update: 2024-09-17 18:47:41 UTC


README

此包为 PHP League 的 OAuth 2.0 Client 提供了 ANS / Pro Sante Connect OAuth 2.0 支持。OAuth 2.0 Client

要求

以下版本的 PHP 已经过测试

  • PHP 8.1

可能还有其他版本也可以使用,但目前尚未进行测试。

使用此包时,需要 ANS Pro Sante Connect 客户端 ID 和客户端密钥。在文档中,这些分别称为 {psc-client-id}{psc-client-secret}

安装

要安装,请使用 composer

composer require groupepsig/oauth2-prosanteconnect

与 Symfony 6.x 一起使用

要使用此包与 Symfony 6.x 一起使用,您需要在您的应用程序中添加一个客户端类,例如以下内容:

namespace App\OAuth2\Client\Provider;

use KnpU\OAuth2ClientBundle\Client\OAuth2Client;
use League\OAuth2\Client\Token\AccessToken;
use GroupePSIH\OAuth2\Client\Provider\ProSanteConnectResourceOwner;

class ProSanteConnectClient extends OAuth2Client
{
    public function fetchUserFromToken(AccessToken $accessToken): ProSanteConnectResourceOwner|\League\OAuth2\Client\Provider\ResourceOwnerInterface
    {
        return parent::fetchUserFromToken($accessToken);
    }

    public function fetchUser(): ProSanteConnectResourceOwner|\League\OAuth2\Client\Provider\ResourceOwnerInterface
    {
        return parent::fetchUser();
    }
}

使用 knpuniversity/oauth2-client-bundle 并在 config/packages/knpu_oauth2_client.yaml 中进行适当的修改

knpu_oauth2_client:
    http_client_options:
        proxy: false
        timeout: 5
    clients:
        prosc:
            type: generic
            provider_class: App\OAuth2\Client\Provider\ProSanteConnect
            client_id: '%env(PROSC_CLIENTID)%'
            client_secret: '%env(PROSC_SECRET)%'
            redirect_route: 'prosc_oauth_check'
            redirect_params: {}
            provider_options: {'dev': true}

security.yaml

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            lazy: true
            form_login:
                login_path: prosc_oauth_login
                # for Gitlab (test)
                # login_path: gitlab_oauth_login
            guard:
                authenticators:
                    - App\Security\ProSCAuthenticator
                    # for Gitlab (test)
                    # - App\Security\GitlabAuthenticator

ProSCAuthenticator 是一个扩展 SocialAuthenticator 的类,并包含您的业务逻辑。