Skip to content
PHP OAUTH2 authentication API - Azure, Facebook, Github, Google, Microsoft, Naver
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

OAUTH2 pear package

GitHub license


Copyright (c) 2019 JoungKyun.Kim <> All rights reserved

This program is under BSD license


This is OAUTH2 login tool and support follow vendors:

  • Google
  • Facebook
  • Github
  • Naver
  • Kakao
  • Microsoft


We recommand to install with pear command cause of dependency pear packages.

1. use pear command

[root@host ~]$ # add pear channel ''
[root@host ~]$ pear channel-discover
Adding Channel "" succeeded
Discovery of channel "" succeeded
[root@host ~]$ # add OAUTH2 pear package
[root@host ~]$ pear install oops/OAUTH2
downloading OAUTH2-1.0.9.tgz ...
Starting to download OAUTH2-1.0.9.tgz (10,893 bytes)
....done: 10,893 bytes
downloading HTTPRelay-1.0.5.tgz ...
Starting to download HTTPRelay-1.0.5.tgz (5,783 bytes)
...done: 5,783 bytes
downloading myException-1.0.2.tgz ...
Starting to download myException-1.0.2.tgz (3,048 bytes)
...done: 3,048 bytes
install ok: channel://
install ok: channel://
install ok: channel://
[root@host ~]$

If you wnat to upgarde version:

[root@host ~]$ pear upgrade oops/OAUT2

2. install by hand

Get last release at and uncompress pakcage within PHP include_path.

You must need follow dependency pear packages:


Refence siste:

reference is written by Korean. If you can't read korean, use google translator.

session_start ();

require_once 'OAUTH2.php';

set_error_handler ('myException::myErrorHandler');

// Callback URL is this page.
$callback = sprintf (
    $_SERVER['HTTPS'] ? 'https' : 'http',

$appId = (object) array (
    'vendor'   => 'google',
    'id'       => 'APPLICATION_ID',
    'secret'   => 'APPLICATION_SECRET_KEY',
    'callback' => $callback,

try {
    $oauth2 = new oops\OAUTH2 ($appId);

    // If you want to logout, give logout parameter at callback url.
    // If you need redirect after logout, give redrect parameter.
    // For example:
    //  http://callback_url?logout&redirect=http%3A%2F%2Fredirect_url
    if ( isset ($_GET['logout']) ) {
        unset ($_SESSION['oauth2']);

        if ( $_GET['redirect'] )
            Header ('Location: ' . $redirect);

        printf ('%s Complete logout', strtoupper ($appId->vendor));

    $user = $oauth2->Profile ();
    $uid = sprintf ('%s:%s', $appId->vendor, $user->id);
    $_SESSION['oauth2'] = (object) array (
        'uid' => $uid,
        'name' => $user->name,
        'email' => $user->email,
        'img' => $user->img,
        'logout' => $callback . '?logout'

    print_r ($_SESS['oauth2']);
} catch ( myException $e ) {
    echo $e->Message () . "\n";
    print_r ($e->TraceAsArray);
    $e->finalize ();
You can’t perform that action at this time.