PHPackages                             codebar-ag/laravel-auth - 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. codebar-ag/laravel-auth

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

codebar-ag/laravel-auth
=======================

This is my package laravel-auth

v3.0(2y ago)03.4kMITPHPPHP ^8.1CI passing

Since Sep 7Pushed 1y agoCompare

[ Source](https://github.com/codebar-ag/laravel-auth)[ Packagist](https://packagist.org/packages/codebar-ag/laravel-auth)[ Docs](https://github.com/codebar-ag/laravel-auth)[ RSS](/packages/codebar-ag-laravel-auth/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (19)Versions (17)Used By (0)

[![](https://camo.githubusercontent.com/8397ac4de2d4bba4e6593ca1072dc2208e018de6436c13d3e08fbee25e484a90/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230417574682e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d636f64656261722d61672532466c61726176656c2d61757468267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d416e2b6f70696e696f6e617465642b7761792b746f2b61757468656e7469636174652b696e2b6c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313735707826696d616765733d646f63756d656e742d7265706f7274)](https://camo.githubusercontent.com/8397ac4de2d4bba4e6593ca1072dc2208e018de6436c13d3e08fbee25e484a90/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230417574682e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d636f64656261722d61672532466c61726176656c2d61757468267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d416e2b6f70696e696f6e617465642b7761792b746f2b61757468656e7469636174652b696e2b6c61726176656c266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313735707826696d616765733d646f63756d656e742d7265706f7274)

[![Latest Version on Packagist](https://camo.githubusercontent.com/47f4918273ad480624fc589a04748d4b96974c91d8d3ef15fdfa9c813e6d7abe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64656261722d61672f6c61726176656c2d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codebar-ag/laravel-auth)[![GitHub-Tests](https://github.com/codebar-ag/laravel-auth/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/codebar-ag/laravel-auth/actions/workflows/run-tests.yml)[![GitHub Code Style](https://github.com/codebar-ag/laravel-auth/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=main)](https://github.com/codebar-ag/laravel-auth/actions/workflows/fix-php-code-style-issues.yml)[![Total Downloads](https://camo.githubusercontent.com/40308fe1bb05e271661a0885373c31c1e5d358ff4bc3ea52e01045149023ca88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64656261722d61672f6c61726176656c2d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codebar-ag/laravel-auth)

This package was developed to give you a quick start to authenticate in laravel. It is opinionated and uses the following packages:

💡 What is Laravel Auth?
-----------------------

[](#-what-is-laravel-auth)

Laravel Auth is an internal Laravel Nova Authentication replacement to gain more control over authorizing into Laravel Nova.

🛠 Requirements
--------------

[](#-requirements)

### &gt; = v1.0

[](#--v10)

- PHP: `^8.2`
- Laravel: `^10.*`
- Microsoft SSO

⚙️ Installation
---------------

[](#️-installation)

You can install the package via composer:

```
composer require codebar-ag/laravel-auth
```

Add the following script to your `composer.json` file:

```
"scripts": {
    "post-update-cmd": [
      "@php artisan vendor:publish --tag=auth-assets --ansi --force"
    ],
}
```

Add configuration to your `config/services.php` file:

```
'microsoft' => [
    'client_id' => env('MICROSOFT_CLIENT_ID'),
    'client_secret' => env('MICROSOFT_CLIENT_SECRET'),
    'redirect' => env('MICROSOFT_REDIRECT_URI'),
    'tenant' => env('MICROSOFT_TENANT_ID'),
    'include_tenant_info' => true,
],
```

Add the following environment variables to your `.env` file:

```
MICROSOFT_CLIENT_ID=your-client-id
MICROSOFT_CLIENT_SECRET=your-client-secret
MICROSOFT_REDIRECT_URI="${APP_URL}/auth/service/microsoft/redirect"
MICROSOFT_TENANT_ID=your-tenant-id
```

⚠️ You need to provide a publicly accessible URL for the `MICROSOFT_REDIRECT_URI` environment variable. You can use [expose](https://expose.dev/) or [ngrok](https://ngrok.com/) for local development.

```
APP_URL=https://your-expose-or-ngrok-url.com

# ✅ This is recommended for production as well:
MICROSOFT_REDIRECT_URI="${APP_URL}/auth/service/microsoft/redirect"
```

Add the following trait to your `User` model:

```
use CodebarAg\LaravelAuth\Traits\HasAuthProviders;
```

Update your `App\Http\Middleware\Authenticate` middleware:

```
...
protected function redirectTo(Request $request): ?string
{
-    return $request->expectsJson() ? null : route('login');
+   return $request->expectsJson() ? null : route('auth.login');
}
```

Finally, run the following command:

```
php artisan auth:install
```

💉 Tests
-------

[](#-tests)

If you wish to add pest tests, run the following command:

```
php artisan auth:install-tests
```

Next add the following to your `phpunit.xml` file:

```

    tests/Auth

```

You will also need to add Auth to your `Pest.php` file:

```
uses(Tests\TestCase::class)->in('Feature', 'Auth');
```

🚏 Routes
--------

[](#-routes)

Below are the following routes provided by this package:

MethodURINameMiddlewareGET | HEAD/auth/loginauth.loginwebPOST/auth/login/storeauth.login.storewebANY/auth/logoutauth.logoutwebGET | HEAD/auth/passwordauth.request-passwordwebPOST/auth/password/storeauth.request-password.storewebPOST/auth/password/resetauth.reset-passwordwebGET | HEAD/auth/password/token/{token}auth.reset-password.storewebGET | HEAD/auth/service/{service}auth.providerwebGET | HEAD/auth/service/{service}/redirectauth.provider.redirectwebGET | HEAD/auth/email/verifyauth.verification.noticewebGET | HEAD/auth/email/verify/{id}/{hash}auth.verification.verifywebPOST/auth/email/verification-notificationauth.verification.sendweb🪐 Nova Adjustments
------------------

[](#-nova-adjustments)

Add the user menu for logout to your `NovaServiceProvider` boot method:

```
use Illuminate\Http\Request;
use Laravel\Nova\Menu\Menu;
use Laravel\Nova\Menu\MenuItem;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        Nova::userMenu(function (Request $request, Menu $menu) {
            return $menu
                ->append(MenuItem::externalLink('Logout', route('auth.logout')));
        });
```

Next in your `nova.php` config add the following:

```
/*
|--------------------------------------------------------------------------
| Nova Routes
|--------------------------------------------------------------------------
|
| These are the routes that are used by Nova to authenticate users.
|
*/

'routes' => [
    'login' => 'auth/login',
],
```

Next in your `NovaServiceProvider` replace the routes method with the following:

Note: you can `not` register routes for `->withAuthenticationRoutes()` or `->withPasswordResetRoutes()` as this will override the changes we made in the `nova.php` config to routes.

```
    /**
     * Register the Nova routes.
     *
     * @return void
     */
    protected function routes()
    {
-        Nova::routes()
-            ->withAuthenticationRoutes()
-            ->withPasswordResetRoutes();
+        Nova::routes();
    }
```

🔧 Configuration file
--------------------

[](#-configuration-file)

You can publish the config file with:

```
php artisan vendor:publish --tag=auth-config
```

This is the contents of the published config file:

```
