barnabynorman/google-auth-wrapper

简化使用Google PHP客户端库的包装器

1.0.4 2023-12-15 07:27 UTC

This package is auto-updated.

Last update: 2024-09-15 09:13:41 UTC


README

使用google-api-php-client并简化配置/使用

使用Composer入门

"require": {
  "barnabynorman/google-auth-wrapper": "^1.0"
}

请确保包含自动加载器

require_once '/path/to/your-project/vendor/autoload.php';

在Google注册: https://github.com/googleapis/google-api-php-client/blob/main/docs/README.md

注意你的

  • 客户端ID
  • 客户端密钥

基本使用

<?php
require_once 'vendor/autoload.php';

// This is your landing place
$redirectUrl = 'https://research.familynorman.org.uk';

$clientId = 'your google client ID';
$clientSecret = 'your google client Secret';

$auth = new GoogleAuthWrapper($clientId, $clientSecret, $redirectUrl);

$authResponse = $auth->doLogin();

if (is_array($authResponse)) {
    // Redirect response as part of login processs
	header('Location: ' . $authResponse['redirect']);

} elseif ($authResponse !== false) {
    // Authenticated with google

    // Test the email address
    switch ($authResponse) {
        case 'bob@test.com':
        // Content here
        break;

        case 'jane@test.com':
        // Content here
        break;

        case 'jane@test.com':
        // Content here
        break;

        case 'mary@test.com':
        // Content here
        break;

        default:
        // Show login page or 404 etc
    }
}