flatline/authy-laravel

此包最新版本(dev-master)的许可证信息不可用。

dev-master 2014-01-30 22:46 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:53:22 UTC


README

这是一个非常简单的laravel包,它封装了Authy_Api。

安装

  1. 安装 flatline/authy-laravel

    $ composer require "flatline/authy-laravel:dev-master"
  2. 更新 app/config/app.php 以激活Authy

    # Add `AuthyLaravelServiceProvider` to the `providers` array
    'providers' => array(
        ...
        'Flatline\AuthyLaravel\AuthyLaravelServiceProvider',
    )
    
    # Add the `Authy` facade to the `aliases` array
    'aliases' => array(
        ...
        'Authy' => 'Flatline\AuthyLaravel\Facades\Authy',
    )

不需要使用外观(facade),因为您可以通过容器请求Authy_Api类,以下方式之一均可:

$authy = app('authy');

// or:

$authy = App::make('Authy_Api');

// or even:

class Foo
{
    protected $authy;

    public function __construct(\Authy_Api $authy)
    {
        $this->authy = $authy;
    }
}

在任何情况下,该类都会在注入之前自动初始化,使用您的相应API密钥和URL(生产或沙盒)。

配置

  1. 生成Authy配置模板文件

    $ php artisan config:publish flatline/authy-laravel
  2. 更新 app/config/packages/flatline/authy-laravel/config.php 并使用您的Authy API密钥,打开或关闭沙盒模式

    return [
        /*
        |--------------------------------------------------------------------------
        | Sandbox Mode
        |--------------------------------------------------------------------------
        |
        | While you're developing your application you might want to work on the
        | sandbox environment. To do so, just set this variable to "true".
        |
        */
        'sandbox' => false,
    
        /*
        |--------------------------------------------------------------------------
        | API Keys
        |--------------------------------------------------------------------------
        |
        | First, you'll need to create your application on the Authy Dashboard.
        | Once you created your Authy App, copy the API keys and paste them here.
        |
        */
        'api_key' => 'your-api-key',
        'sandbox_api_key' => 'your-sandbox-api-key',
    ];