virgantara/unida-apps-support 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

virgantara/unida-apps-support

最新稳定版本:v1.0.4

Composer 安装命令:

composer require virgantara/unida-apps-support

包简介

A collection of UNIDA Gontor Apps Components.

README 文档

README

License PHP Yii2

Welcome to the Apps Support Components package! This collection of Yii2 components simplifies authentication and token management for your applications. Whether you need OAuth2 integration, token handling, or application-based authentication, this package has got you covered! 🌟

📦 Components Overview

Setup

Put this in your params.php or params-local.php

// Previous params codes
'oauth' => [
    'client_id' => 'your-client-id',
    'client_secret' => 'your-client-secret',
    'baseurl' => 'https://your-oauth-server.com',
    'redirectUri' => 'https://your-app.com/callback',
],

Installation

  1. add this to composer.json "repositories"
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/virgantara/Unida-Apps-Support.git"
        }
    ]
  1. add this to composer.json "require"
    "require": {
        "virgantara/unida-apps-support": "dev-master"        
    }
  1. Update your composer by running this code
composer update -vvv
  1. Open your config/web.php, add the following code in components
'components' => [
    ...
    'tokenService' => [
        'class' => 'virgantara\components\TokenService',
    ],
    'aplikasi' => [
        'class' => 'virgantara\components\AplikasiAuth',
        'baseurl' => $params['oauth']['baseurl'], 
    ],
    'tokenManager' => [
        'class' => 'virgantara\components\TokenManager',
    ],
    'oauth2' => [
        'class' => 'virgantara\components\OAuth2Client',
        'tokenValidationUrl' => $params['oauth']['baseurl'], // Endpoint for token validation
        'tokenRefreshUrl' => $params['oauth']['baseurl'],
        'client_id' => $params['oauth']['client_id'],
        'client_secret' => $params['oauth']['client_secret'],
    ],
]
  1. Open your SiteController.php, add the following codes:
    public function actionAuthCallback()
    {
        try {
            $accessToken = Yii::$app->request->get('access_token');
            $refreshToken = Yii::$app->request->get('refresh_token');

            Yii::$app->tokenService->handleAuthCallback($accessToken, $refreshToken);

            return $this->redirect(['site/index']);
        } catch (\Exception $e) {
            return $this->handleException($e);
        }
    }

    protected function handleException($e)
    {
        Yii::$app->session->setFlash('danger', $e->getMessage());
        return $this->redirect(['site/index']);
    }

    public function actionCallback()
    {
        try {
            $receivedJwt = Yii::$app->request->get('state');
            $authCode = Yii::$app->request->get('code');

            Yii::$app->tokenService->handleCallback($receivedJwt, $authCode);

            return $this->redirect(['site/index']);
        } catch (\Exception $e) {
            return $this->handleException($e);
        }
    }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固