PHPackages                             kronthto/laravel-oauth2-login - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. kronthto/laravel-oauth2-login

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

kronthto/laravel-oauth2-login
=============================

Provides a middleware to protect resources requiring an OAuth2 login

v1.13.0(3y ago)2117.5k↓100%8[1 issues](https://github.com/kronthto/laravel-oauth2-login/issues)1MITPHPPHP ^7.4|^8.0

Since May 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kronthto/laravel-oauth2-login)[ Packagist](https://packagist.org/packages/kronthto/laravel-oauth2-login)[ Docs](https://github.com/kronthto/laravel-oauth2-login)[ RSS](/packages/kronthto-laravel-oauth2-login/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (16)Used By (1)

Laravel OAuth2 Login
====================

[](#laravel-oauth2-login)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Latest Stable Version](https://camo.githubusercontent.com/e2cfc3f8d4b583484295e8b3191489cea2c5fe5a610cbacaf2cfef6a6423c47d/68747470733a2f2f62616467652e667572792e696f2f67682f6b726f6e7468746f2532466c61726176656c2d6f61757468322d6c6f67696e2e737667)](https://github.com/kronthto/laravel-oauth2-login/releases)[![Build Status](https://camo.githubusercontent.com/2fb63866fef781d3fd2f4d3c6991f48048bf4d7ddf4ad5a4ee404e3756e400a6/68747470733a2f2f7472617669732d63692e6f72672f6b726f6e7468746f2f6c61726176656c2d6f61757468322d6c6f67696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kronthto/laravel-oauth2-login)

This is a Laravel package that provides a middleware to protect routes requiring an OAuth2 login.

You could describe it as a bridge between Laravel and [league/oauth2-client](https://github.com/thephpleague/oauth2-client).

Features
--------

[](#features)

- OAuth2 client middleware
- Keeps token in session
- Refreshes expired tokens
- (Cached) resource owner info
- Driver to allow integration with `Auth/auth()`

Install
-------

[](#install)

- Using composer: `$ composer require kronthto/laravel-oauth2-login`
- Register the service provider (Auto-Discovery enabled): `Kronthto\LaravelOAuth2Login\ServiceProvider`
- Publish the config file: `$ artisan vendor:publish --provider="Kronthto\LaravelOAuth2Login\ServiceProvider"`
- Put the credentials of your OAuth Provider in the published config

Usage
-----

[](#usage)

Add the `Kronthto\LaravelOAuth2Login\CheckOAuth2` middleware to the routes (-groups) you want to protect.

**Bear in mind that this only ensures that some user is logged in**, if you require further authorization checks those will still have to be implemented. This package stores the resource owner info as an Request-attribute to enable you to do so.

This redirects unauthenticated users. If on some routes you only want to check whether a session by this package exists (for instance to display a login/logout button in your template) use `Kronthto\LaravelOAuth2Login\OnlyCheckOAuth`. It will also refresh tokens and pull up to date resource owner data, but never redirect. On failure it just doesn't set the Request attribute.

### `Auth` guard

[](#auth-guard)

This is optional, as adding the middleware redirects the client anyways if not authenticated. If you want to utilize Policies however you will need to define a custom guard. A driver for it is provided by this package.

In your auth config, add the new guard like this:

```
  'oauth2' => [
    'driver' => 'oauth2', // Config: oauth2login.auth_driver_key
  ]
```

**You will need to assign a higher priority to `CheckOAuth2` than `\Illuminate\Auth\Middleware\Authenticate`**, do this by overriding `$middlewarePriority` in your Http-Kernel.

If you want to add the middleware globally, best do it as route-middleware, in `middlewareGroups.web`, rather than the very global middleware array.

Changelog
---------

[](#changelog)

Please see the [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see the [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 97.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~150 days

Recently: every ~313 days

Total

15

Last Release

1170d ago

PHP version history (4 changes)v1.0.0PHP &gt;=5.6.0

v1.9.0PHP ^7.0.0

v1.11.0PHP ^7.3|^8.0

v1.13.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/87e3465a3a0a19daa8c0f83002b05a245da968ce09d12e2dcaee76359585f193?d=identicon)[kronthto](/maintainers/kronthto)

---

Top Contributors

[![kronthto](https://avatars.githubusercontent.com/u/17156142?v=4)](https://github.com/kronthto "kronthto (74 commits)")[![madagon](https://avatars.githubusercontent.com/u/2950285?v=4)](https://github.com/madagon "madagon (1 commits)")[![subtronic](https://avatars.githubusercontent.com/u/1489572?v=4)](https://github.com/subtronic "subtronic (1 commits)")

---

Tags

authenticationlaravelmiddlewareoauth2middlewarelaraveloauth2aclsessionlogin

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kronthto-laravel-oauth2-login/health.svg)

```
[![Health](https://phpackages.com/badges/kronthto-laravel-oauth2-login/health.svg)](https://phpackages.com/packages/kronthto-laravel-oauth2-login)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[yajra/laravel-acl

Laravel ACL is a simple role, permission ACL for Laravel Framework.

112103.9k1](/packages/yajra-laravel-acl)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2011.0k](/packages/alajusticia-laravel-logins)[hosseinhezami/laravel-permission-manager

Advanced permission manager for Laravel.

403.3k](/packages/hosseinhezami-laravel-permission-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
