4,000 emails/month for free | Mailtrap sends real emails now!

Seamless PropelAuth Integration in Laravel with Earhart

Last updated on by

Seamless PropelAuth Integration in Laravel with Earhart image

Authentication is one of those things many applications need, and Laravel has no shortage of options for Authentication solutions. However, if you're looking for an alternative, then PropelAuth could be a good option to try. There is a PropelAuth Socialite Provider available, and to make the integration even easier, developer Elliot Ali has created a Laravel package called Earhart, which makes it even more seamless.

Features

  • Integrates with Laravel Socialite
  • Some initial routes and controllers are already set up and loaded to handle PropelAuth Accounts, Organizations, and Members
  • A controller to handle webhook requests from PropelAuth, which fires events you can listen for in your application.

A Quick Example

As with other Socialite providers, you will need to sign up for PropelAuth and complete some configuration before using this package. This includes creating an OAuth2 provider within PropelAuth and copying down your Client ID and Client Secret. Follow the PropelAuth docs to learn how to setup this OAuth provider.

Once done, in your .env file, add the following environment variables with the appropriate values:

PROPELAUTH_CLIENT_ID="tbc"
PROPELAUTH_CLIENT_SECRET="tbc"
PROPELAUTH_CALLBACK_URL=https://localhost:8000/auth/callback
PROPELAUTH_AUTH_URL=https://0000000000.propelauthtest.com
PROPELAUTH_SVIX_SECRET="whsec_tbd"
PROPELAUTH_API_KEY="tbc"

And then, in config/services.php, add the following:

'propelauth' => [
'client_id' => env('PROPELAUTH_CLIENT_ID'),
'client_secret' => env('PROPELAUTH_CLIENT_SECRET'),
'redirect' => env('PROPELAUTH_CALLBACK_URL'),
'auth_url' => env('PROPELAUTH_AUTH_URL'),
'svix_secret' => env('PROPELAUTH_SVIX_SECRET'),
'api_key' => env('PROPELAUTH_API_KEY'),
]

With that now set up, you can add a login link to your Blade template using the included auth.redirect route, which sends your users to your PropelAuth login page (which is customizable from your PropelAuth Dashboard).

<a href="{{ route('auth.redirect') }}">Login</a>
Sample PropelAuth Login page
Sample PropelAuth Login page

Even though this package handles some of the boilerplate code for integrating with PropelAuth, it’s still up to you to create a /auth/callback route that saves the user to your application's database on successful login.

This route could look something like this:

Route::get('/auth/callback', function(Request $request) {
$propelUser = Socialite::driver('propelauth')->user();
$rawUser = $propelUser->getRaw();
 
$user = User::updateOrCreate([
'propel_id' => $propelUser->id,
], [
'name' => $rawUser['first_name'] . ' ' . $rawUser['last_name'],
'email' => $propelUser->email,
'propel_access_token' => $propelUser->token,
'propel_refresh_token' => $propelUser->refreshToken,
'avatar' => $rawUser['picture_url'],
'data' => json_encode($rawUser),
'email_verified_at' => $rawUser['email_confirmed'] ? now() : null,
]);
 
Auth::login($user);
 
return redirect('/dashboard');
})->name('auth.callback');

You’ll notice in the example above that we have used $propelUser->getRaw(). By default, after a user successfully logs in, the Socialite driver for PropelAuth returns only the user's email, id, and tokens. But if you require some more information about the user, for instance, to populate other user details in your database, then you can retrieve the raw user array.

You will also need to create a /auth/logout route, which will invalidate the refresh_token we received during login and also log the user out:

Route::get('/auth/logout', function(Request $request){
 
$response = Http::withHeaders([
'Content-Type' => 'application/json',
])->post(config('services.propelauth.auth_url') . '/api/backend/v1/logout', [
'refresh_token' => Auth::user()->propel_refresh_token,
]);
 
if ($response->failed()) {
Log::debug('Failed to log out from PropelAuth', ['response' => $response->body()]);
}
 
Auth::logout();
 
return redirect('/');
})->name('auth.logout');

And in a similar manner to our Login link, you should add your Logout link in your Blade template:

<a href="{{ route('auth.logout') }}">Logout</a>

Learn more about this package (including the other available routes and events) and view the source code on GitHub.

Yannick Lyn Fatt photo

Staff Writer at Laravel News and Full stack web developer.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
A new beta of Laravel Wayfinder just dropped image

A new beta of Laravel Wayfinder just dropped

Read article
Ben Bjurstrom: Laravel is the best Vibecoding stack for 2026 image

Ben Bjurstrom: Laravel is the best Vibecoding stack for 2026

Read article
Laravel Altitude - Opinionated Claude Code agents and commands for TALL stack development image

Laravel Altitude - Opinionated Claude Code agents and commands for TALL stack development

Read article
JSON:API Resource in Laravel 12.45 image

JSON:API Resource in Laravel 12.45

Read article
Caching With MongoDB for Faster Laravel Apps image

Caching With MongoDB for Faster Laravel Apps

Read article
Laravel 12.44 Adds HTTP Client afterResponse() Callbacks image

Laravel 12.44 Adds HTTP Client afterResponse() Callbacks

Read article