承接 ddruganov/yii2-api-auth-proxy 相关项目开发

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

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

ddruganov/yii2-api-auth-proxy

Composer 安装命令:

composer require ddruganov/yii2-api-auth-proxy

包简介

Authentication proxy tools for yii2

README 文档

README

An authentication proxy component library that connects your app with the yii2-api-auth server

Installation

composer require ddruganov/yii2-api-auth-proxy

Configuration

  1. Add this to your app's main config:
...
    'components' => [
        AccessTokenProviderInterface::class => HeaderAccessTokenProvider::class,
        AuthServiceInterface::class => AuthService::class,
        AuthServiceRequestInterface::class => GuzzleAuthServiceRequest::class
    ],
    'controllerMap' => [
        'auth' => AuthController::class
    ],
...
  1. Add this to your app's params config:
...
    'authentication' => [
        'externalService' => [
            'url' => 'https://server-that-has-yii2-api-auth-installed'
        ]
    ]
...

How to use

  • POST /auth/login with an access token that you got from logging in on the yii2-api-auth server to check that your log in is valid
  • POST /auth/refresh with your refresh token to get a fresh pair of tokens form the main server
  • POST /auth/logout to send a logout request to the main server
  • Use Yii::$app->get(AuthServiceInterface::class)->getUser() to get the ddruganov\Yii2ApiAuthProxy\components\AuthServiceUser
  • Attach AuthFilter as a behavior to your ApiController to only allow authenticated users to access the endpoints
  • Attach RbacFilter as a behavior to your ApiController to only allow users with specific permissions to access the endpoints

Extending AuthServiceInterface::getUser() example

class YourAuthService extends Yii2ApiAuthProxyAuthService
{
    public function getUser(string $accessToken): YourAuthServiceUser
    {
        $baseUrl = Yii::$app->params['authentication']['externalService']['url'];

        $result = Yii::$app->get(AuthServiceRequestInterface::class)->make(
            method: AuthServiceRequestInterface::GET,
            url: $baseUrl . '/' . self::CURRENT_USER_ENDPOINT,
            data: [],
            accessToken: $accessToken
        );

        if (!$result->isSuccessful()) {
            throw new Exception('Error getting user from a remote auth server');
        }

        return new YourAuthServiceUser($result->getData());
    }
}

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固