emidas/oauth2-invision

此软件包提供Invision的OAuth 2支持,并兼容League的OAuth 2.0客户端。

dev-main 2023-10-12 07:04 UTC

This package is auto-updated.

Last update: 2024-09-12 09:19:22 UTC


README

此软件包提供Invision的OAuth 2支持,并兼容League的OAuth 2.0客户端。


🚀 下载和安装

此软件包可在Packagist找到。您可以直接使用Composer命令composer req emidas/oauth2-invision进行安装。

📖 示例

<?php

require __DIR__ . '/vendor/autoload.php';
session_start();

$invisionProvider = new emidas\OAuth2\Client\InvisionProvider([
    'baseUrl' => '', // The base URL of your Invision Community
    'clientId' => '', // The client ID of your application
    'clientSecret' => '', // The client secret of your application
    'redirectUri' => '' // The callback URI where the user will be redirected
]);

if (isset($_GET['code'])) {
    if ($_SESSION['oauth2_state'] !== $_GET['state'])
        exit('The returned state doesn\'t match with your local state.');
    $invisionToken = $invisionProvider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
    $invisionUser = $invisionProvider->getResourceOwner($invisionToken);
    echo 'Your primary group name is: ' . $invisionUser->getPrimaryGroup()->getName();
    echo 'Your email is: ' . $invisionUser->getEmail();
} else {
    $oauthUrl = $invisionProvider->getAuthorizationUrl();
    $_SESSION['oauth2_state'] = $invisionProvider->getState();
    header('Location: ' . $oauthUrl);
}