red-dott/google-oauth-login-php
Composer 安装命令:
composer require red-dott/google-oauth-login-php
包简介
This a simple package for php for authenticating user from Google using the OAuth 2.0
README 文档
README
A simple handler for php to use OAuth2.0 for authenticating using google
At first a google application has to be set up for client ID and Client Secret. Go to https://console.cloud.google.com/apis/credentials?project=life-good-315813
Set up OAuth Consent Screen
Give app name -> centact email address -> application home page url (here localhost/Myapp) -> give test email address and continue and Save.
Go to Credentials
Create Credential ->
Oauth Client Id ->
Web Application ->
add web app name ->
add redirect uri (the url where google will send back its response such as localhost/login.php)
Download the config JSON file containing client ID and Client Secret
Install composer (php package manager) from here https://getcomposer.org/download/
Setup using composer
composer require red-dott/google-oauth-login-php:dev-main
Set up in your project with github
In your composer.json file add
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Amadeus-911/red-dot-Google-Login-php-package.git"
}
],
"require": {
"red-dott/google-oauth-login-php": "dev-main"
}
}
on root folder of you project run
composer install
Setup in your project
- refer to the sample/login.php
import it in your php file
require_once 'vendor/autoload.php';
use RedDot\GoogleOauthLoginPhp\GoogleClient;
First create the GoogleClient with your google app client_id and client_secret then generate authUrl where the login button will hit
$client = new GoogleClient($client_id, $client_secret, $redirect_uri);
$authUrl = $client->buildAuthUrl();
add it to your google sign in button like this
<a style="text-decoration:none" href="<?php echo $authUrl?>">
<button class="google-button">
</button>
</a>
get access token
$code = $_GET['code'];
$accessToken = $client->getAccessToken($code);
retrive user data using the access token
$user = $client->getUserInfo($accessToken);
There is a sample project given for your reference. Use your applications CLIENT_ID, CLIENT_SECRET, REDIRECT_URI in place of the placeholders
red-dott/google-oauth-login-php 适用场景与选型建议
red-dott/google-oauth-login-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 red-dott/google-oauth-login-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 red-dott/google-oauth-login-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-17