承接 oneduo/laravel-recaptcha-enterprise 相关项目开发

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

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

oneduo/laravel-recaptcha-enterprise

最新稳定版本:v0.5.0

Composer 安装命令:

composer require oneduo/laravel-recaptcha-enterprise

包简介

This is my package laravel-recaptcha-enterprise

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads codecov

Wrapper to use Google reCAPTCHA Enterprise with Laravel. Provides a handy validation rule to verify your token's score.

Table of Contents

Prerequisites

TLDR; You may want to follow the official documentation to get started.

1. Enable the reCAPTCHA Enterprise API

On your Google Cloud console, go ahead and enable the reCAPTCHA Enterprise API.

2. Create a service account

Create a service account with the following roles:

  • reCAPTCHA Enterprise Agent

3. Create a key

Create a key for your service account and download it as a JSON file.

4. Use your credentials

Use your credentials by setting the appropriate values in config/recaptcha-enterprise.php or by setting the environment variables.

Installation

You can install the package via composer:

composer require oneduo/laravel-recaptcha-enterprise

Configuration

You can publish the config file with:

php artisan vendor:publish --tag="recaptcha-enterprise-config"

This is the contents of the published config file, you are required to set the variables accordingly:

return [
    'site_key' => env('RECAPTCHA_ENTERPRISE_SITE_KEY'),

    'use_credentials' => env('RECAPTCHA_ENTERPRISE_USE_CREDENTIALS', 'default'),

    'credentials' => [
        'default' => [
            'type' => 'service_account',
            'project_id' => env('RECAPTCHA_ENTERPRISE_PROJECT_ID'),
            'private_key_id' => env('RECAPTCHA_ENTERPRISE_PRIVATE_KEY_ID'),
            'private_key' => env('RECAPTCHA_ENTERPRISE_PRIVATE_KEY'),
            'client_email' => $email = env('RECAPTCHA_ENTERPRISE_CLIENT_EMAIL'),
            'client_id' => env('RECAPTCHA_ENTERPRISE_CLIENT_ID'),
            'auth_uri' => 'https://accounts.google.com/o/oauth2/auth',
            'token_uri' => 'https://accounts.google.com/o/oauth2/token',
            'auth_provider_x509_cert_url' => 'https://www.googleapis.com/oauth2/v1/certs',
            'client_x509_cert_url' => 'https://www.googleapis.com/robot/v1/metadata/x509/' . $email,
        ],
    ],
];

Usage

You may start using the reCAPTCHA validation rule by implementing the available Oneduo\RecaptchaEnterprise\Rules\Recaptcha rule in your business logic, here's an example of a FormRequest implementation:

<?php

declare(strict_types=1);

namespace Oneduo\RecaptchaEnterprise\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Oneduo\RecaptchaEnterprise\Rules\Recaptcha;

class TestRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'g-recaptcha-response' => ['required', new Recaptcha()],
        ];
    }

    public function authorize(): bool
    {
        return true;
    }
}

Configuring the threshold

When validating a token, you may want to set a threshold for the score. You can do so setting the score_threshold config value:

'score_threshold' => 0.7,

Default threshold is 0.5

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 60
  • Watchers: 2
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-14