steelze / google-one-tap

Google One Tap 登录 For Laravel

v0.2.0-beta 2022-07-26 04:54 UTC

This package is auto-updated.

Last update: 2024-09-29 06:03:23 UTC


README

Latest Version on Packagist Total Downloads GitHub Actions

此包将谷歌的一键登录集成到Laravel项目中。

安装

您可以通过composer安装此包

composer require steelze/google-one-tap

服务提供者将自动注册

接下来,您必须发布配置文件

php artisan vendor:publish --tag=google-one-tap

这是默认配置文件的内容。在这里您可以修改配置。

return [

    /*
    |--------------------------------------------------------------------------
    | Google Client ID
    |--------------------------------------------------------------------------
    |
    | This value is your Google app's client ID, which is found
    | and created in the Google Developers Console.
    |
    */

    'client_id' => env('GOOGLE_CLIENT_ID'),

    /*
    |--------------------------------------------------------------------------
    | Enable Google One Tap
    |--------------------------------------------------------------------------
    |
    | This determines whether to display One tap or not. The default value is
    | true. Google One tap will not be displayed when this value is false
    |
    */

    'enable' => (bool) env('ENABLE_GOOGLE_ONE_TAP', true),

    /*
    |--------------------------------------------------------------------------
    | Login URI
    |--------------------------------------------------------------------------
    |
    | This specifies the the URI of your login endpoint. The ID token credential
    | response is posted to this endpoint when no callback function is defined
    | and a user clicks on the One Tap buttons, or automatic sign takes place.
    |
    */

    'login_uri' => '',

    /*
    |--------------------------------------------------------------------------
    | Cancel on Outside Click
    |--------------------------------------------------------------------------
    |
    | This attribute sets whether or not to cancel the One Tap request if the
    | user clicks outside of the prompt. The default value is true. To disable it,
    | set the value to false.
    |
    */

    'cancel_on_tap_outside' => false,

    /*
    |--------------------------------------------------------------------------
    | Context
    |--------------------------------------------------------------------------
    |
    | Changes the text of the title and messages shown in the One Tap prompt
    | Supported: "use", "signin", "signup"
    |
    */

    'context' => 'use',

    /*
    |--------------------------------------------------------------------------
    | itp_support
    |--------------------------------------------------------------------------
    |
    | This field determines if the upgraded One Tap UX should be enabled on
    | browsers that support Intelligent Tracking Prevention (ITP).
    | The default value is false. See the following for further
    | information: https://developers.google.com/identity/gsi/web/guides/features#upgraded_ux_on_itp_browsers
    |
    */

    'itp_support' => false,

    /*
    |--------------------------------------------------------------------------
    | Custom Attributes
    |--------------------------------------------------------------------------
    |
    | Custom data attributes, which are sent to your login endpoint with the
    | ID token retrieved from Google.
    |
    */
    'custom' => [

    ]
];

使用方法

更新配置文件中的登录URI。指定的URI将被谷歌调用,凭证将被发送到此端点。

// config/google-one-tap.php
/*
|--------------------------------------------------------------------------
| Login URI
|--------------------------------------------------------------------------
|
| This specifies the the URI of your login endpoint. The ID token credential
| response is posted to this endpoint when no callback function is defined
| and a user clicks on the One Tap buttons, or automatic sign takes place.
|
*/

'login_uri' => '',

在路由回调处理程序中,调用GoogleOneTapFacade::getUserFromProvider()方法。此方法将返回已登录用户详情的数组,或者在发生错误时抛出异常。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全性

如果您发现任何安全相关的问题,请通过电子邮件sogungbure@gmail.com联系,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件