承接 red-dott/google-oauth-login-php 相关项目开发

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

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-17