定制 stia/authid-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

stia/authid-php

最新稳定版本:1.0.2

Composer 安装命令:

composer require stia/authid-php

包简介

SDK / Plugin to handle Authenticator for Auth ID

README 文档

README

  • Laravel 10 or later
  • PHP 8.1 or later

Instalation Guide

Install dependency with composer

composer require stia/authid-php

Publish the config file

php artisan vendor:publish --provider="Stia\AuthidPhp\AuthIDServiceProvider"

Run the migration

php artisan migrate

To enable 2 FA, add the following code to the User model

use TwoFactorAuthenticatable;

Example:

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
    use TwoFactorAuthenticatable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
    ...

Method Usage

Check is user already have recovery codes

$user = User::find($id);
$isEnabled = $user->hasEnabledTwoFactorAuthentication();

return $isEnabled;

Generate new recovery codes

$user = User::find($id);
$user->generateNewRecoveryCode();

Get user recovery codes

$user = User::find($id);
$recoveryCodes = $user->recoveryCodes();

return $recoveryCodes;

Enable 2FA and generate QR code

namespace App\Http\Controllers;

use Stia\AuthidPhp\Actions\EnableTwoFactorAuthentication;

class UserController extends Controller
{
    public function enableTwoFactorAuthentication(EnableTwoFactorAuthentication $enableAction)
    {
        $user = auth()->user();
        $enableAction($user);
        return $user->twoFactorQrCodeSvg();
    }
}

Validate 2FA

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Stia\AuthidPhp\Actions\EnableTwoFactorAuthentication;
use Stia\AuthidPhp\Actions\IsTwoFactorAuthenticationValid;

class UserController extends Controller
{
    public function validateTwoFactorAuthentication(Request $request, IsTwoFactorAuthenticationValid $confirm)
    {
        if ($confirm($request->user(), $request->code)) {
            return 'OK';
        }
        
        return 'Code not valid';
    }

...

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-02-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固