carry0987/falcon

Falcon - A versatile PHP framework designed for seamless integration of third-party social logins. Supports major services including Google, Facebook, Twitter, etc, delivering simple and secure authentication via a unified interface and design patterns.

1.0.4 2024-01-14 12:26 UTC

This package is auto-updated.

Last update: 2024-05-21 08:09:35 UTC


README

Packgist
Falcon is a versatile PHP framework designed for seamless integration of third-party social platform login mechanisms.
It offers simple and secure user authentication through a unified interface and design patterns, making it easy to implement and maintain.
Currently, it supports the following major services:

  • GitHub
  • Google
  • Facebook
  • Instagram
  • Twitter
  • Reddit
  • Discord
  • Line
  • Telegram

Whether you're developing a new application or enhancing an existing system, Falcon can help you quickly implement social login features while ensuring user data security and privacy.

Features

  • Unified Interface: Operate all supported social services using standardized methods.
  • Easy Integration: Integrate quickly into your project with intuitive configuration and clear documentation.
  • Security: Implements the best current security practices to safeguard the login process and data.
  • Flexible Design: Easily add or remove specific social services without affecting the existing system architecture.
  • Open Source Support: Benefit from the continuous improvements and support of the open-source community.

Installation

Install Falcon into your project with Composer:

composer require carry0987/falcon

Usage Example

First, set up the credentials and other configuration information for each third-party service in your project:

$config = [
    'providers' => [
        'github' => [
            'client_id' => 'your_github_client_id',
            'client_secret' => 'your_github_client_secret',
            'redirect_uri' => 'https://your-website.com/path/to/callback.php?provider=github'
        ],
        'line' => [
            'client_id' => 'your_line_client_id', // Channel ID
            'client_secret' => 'your_line_client_secret', // Channel secret
            'redirect_uri' => 'https://your-website.com/path/to/callback.php?provider=line'
        ],
        'telegram' => [
            'client_id' => 'your_telegram_client_id', // Bot username
            'client_secret' => 'your_telegram_client_secret', // Bot token
            'redirect_uri' => 'https://your-website.com/path/to/callback.php?provider=telegram'
        ],
        // Configuration for other third-party login providers...
    ],
];

Next, create an instance of Falcon and initiate the login process with the chosen third-party provider:

$falcon = new \carry0987\Falcon\Falcon($config);
$providerName = $_GET['provider'] ?? 'default';
$provider = $falcon->createProvider($providerName);

// Start the OAuth login process
if (!isset($_GET['code'])) {
    $loginUrl = $provider->authorize();
    // Redirect user to the login page
    header('Location: ' . $loginUrl);
    exit;
}

// Handle the callback and retrieve user information
if ($providerName === 'telegram') {
    // Special handling for Telegram login flow...
} else {
    $accessToken = $provider->getTokenWithAuthCode($_GET['code']);
    $user = $provider->getUser();
    
    // Output user information
    echo "<pre>" . print_r($user, true) . "</pre>";
}

To end the login session, you can revoke the access token:

if (isset($_GET['logout'])) {
    $provider->revokeAccessToken($_GET['access_token'] ?? null);
    // Redirect back to the login page or homepage
    header('Location: ?provider=' . $providerName);
    exit;
}

You can add more standard OAuth processing logic to your code, such as handling error states, redirecting to other pages, etc.

Support

If you have any issues, please open an issue on our GitHub repository.

Enjoy using Falcon in your project!