zydnrbrn/authkit-php

This package provides a convenient way to integrate with AuthKit OAuth 2.0 authentication system in your Laravel applications.

v0.1.2 2025-05-06 04:48 UTC

This package is auto-updated.

Last update: 2025-05-06 04:49:56 UTC


README

Latest Version on Packagist Tests Total Downloads

This package provides a convenient way to integrate with AuthKit OAuth 2.0 authentication system in your Laravel applications. AuthKit allows you to easily implement secure authentication in your applications with support for OAuth 2.0 flows and API authentication.

Installation

You can install the package via composer:

composer require zydnrbrn/authkit-php

After installing, publish the configuration file:

php artisan vendor:publish --provider="Zydnrbrn\AuthKit\Providers\AuthKitServiceProvider"

Configuration

Add the following variables to your .env file:

AUTHKIT_CLIENT_ID=your-client-id
AUTHKIT_CLIENT_SECRET=your-client-secret
AUTHKIT_REDIRECT_URI=https://your-app.com/callback
AUTHKIT_API_URL=https://api.authkit.com

Usage

OAuth Authorization Flow

use Zydnrbrn\AuthKit\Facades\AuthKit;

class AuthController extends Controller
{
    public function redirect()
    {
        return redirect()->to(AuthKit::getAuthorizationUrl());
    }

    public function callback(Request $request)
    {
        // Exchange authorization code for token
        $token = AuthKit::exchangeCodeForToken($request->code);

        // Get the user
        $user = AuthKit::getUserFromToken($token);

        // Log the user in
        Auth::guard('authkit')->login($user);

        return redirect('/dashboard');
    }
}

Using the AuthKit Guard

In your config/auth.php file:

'guards' => [
    // ...
    'authkit' => [
        'driver' => 'authkit',
        'provider' => 'authkit_users',
    ],
],

'providers' => [
    // ...
    'authkit_users' => [
        'driver' => 'authkit',
    ],
],

Now you can use the guard in your application:

// Check if the user is authenticated
if (Auth::guard('authkit')->check()) {
    // User is logged in
}

// Get the authenticated user
$user = Auth::guard('authkit')->user();

Token Management

// Refresh an expired token
$newToken = AuthKit::refreshToken($oldToken->getRefreshToken());

// Revoke a token
AuthKit::revokeToken($token->getAccessToken());

// Validate a token
$isValid = AuthKit::validateToken($token->getAccessToken());

Events

This package provides several events you can listen for:

  • Zydnrbrn\AuthKit\Events\TokenAcquired: Fired when a new token is acquired
  • Zydnrbrn\AuthKit\Events\TokenRefreshed: Fired when a token is refreshed
  • Zydnrbrn\AuthKit\Events\AuthenticationFailed: Fired when authentication fails

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Similar code found with 1 license type