virgantara/unida-apps-support
最新稳定版本:v1.0.4
Composer 安装命令:
composer require virgantara/unida-apps-support
包简介
A collection of UNIDA Gontor Apps Components.
README 文档
README
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
- add this to composer.json
"repositories"
"repositories": [ { "type": "vcs", "url": "https://github.com/virgantara/Unida-Apps-Support.git" } ]
- add this to composer.json
"require"
"require": { "virgantara/unida-apps-support": "dev-master" }
- Update your composer by running this code
composer update -vvv
- Open your
config/web.php, add the following code incomponents
'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'], ], ]
- 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
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-18