Posts tagged with authentication

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

Pragmatically testing multi-guard authentication in Laravel

by Freek Van der Herten – 2 minute read

Last week our team launched Mailcoach, a self-hosted solution to send out email campaigns and newsletters. Rather than being the end, laughing something is the beginning of a journey. Users start encountering bugs and ask for features that weren't considered before.

One of those features requests we got, is the ability the set the guard to be used when checking if somebody is allowed to access the Mailcoach UI.

In this blog post, I'd like to show you how we implemented and tested this.

Read more

Sending a welcome notification to new users of a Laravel app

by Freek Van der Herten – 7 minute read

My team and I currently building Mailcoach, a solution to self-host newsletters and email campaigns. In Mailcoach you can create new users to use the app.

How should these new users be onboarded? The easy way out would be to send these new users a default password reset notification to those users, but that isn't a good first experience. The default auth scaffold by Laravel doesn't help us here: it only contains functionality to log in and to let users register themselves.

To onboard new users created by other users, I've created a package called laravel-welcome-notification which can send a welcome notification to new users that allows them to set an initial password.

In this blogpost I'd like to explain how you can use the package).

Read more

How to build screens for users, permissions and roles in a Laravel app

One of our more popular packages is laravel-permission. It enables you to easily save roles and permissions in the database. It hooks into Laravel's native authorization capabilities. Allthough it's quite powerful, the package doesn't come with any UI out of the box.

If you do need a UI for this in your projects you're in luck. On Scotch.io Caleb Oki wrote down an extensive tutorial on how you can build screens to manage users, permissions and roles that use our package.

When building an application, we often need to set up an access control list (ACL). An ACL specifies the level of permission granted to a user of an application. For example a user John may have the permission to read and write to a resource while another user Smith may have the permission only to read the resource.

In this tutorial, I will teach you how to add access control to a Laravel app using laravel-permission package. For this tutorial we will build a simple blog application where users can be assigned different levels of permission.

https://scotch.io/tutorials/user-authorization-in-laravel-54-with-spatie-laravel-permission

Read more

How to Scan Fingerprints with Async PHP and React Native

In an amazing article on SitePoint, Christopher Pitt demonstrates how to create an async PHP server that can requests a fingerprint scan on the client side. He uses React Native, WebSocket, an async PHP server, PHP preprocessing, ... Really amazing stuff.

I’m going to describe the process of building custom multi-factor authentication for all transactions. I don’t want to do the usual (and boring on its own) SMS or push notification one-time-password stuff. I want to build a fingerprint scanner right into my phone.

In this tutorial, we’re going to look at how to set up a simple iOS app using React Native. We will also set up an asynchronous HTTP server, with a web socket connection to the app.

We will follow this up by adding fingerprint scanning capabilities to the app, and asking for these fingerprint scans from the HTTP server. Then we will build an endpoint through which GET requests can request a fingerprint scan and wait for one to occur.

https://www.sitepoint.com/scan-fingerprints-async-php-react-native/

Read more

Manage permission and roles in a Laravel app

A few week ago we released a new major version of laravel-permission. This package makes it easy to store permission and roles in the database. Our package plays nice with Laravel's Gate and has support for multiple guards.

In a new post on his blog Saqueib Ansari shows how you can create an interface to assign permissions and roles to a user using our package.

Laravel comes with Authentication and Authorization out of the box, I have implemented many role and permissions based system in the past, using laravel, it’s peace of cake. In this post, we are going to implement a fully working and extensible roles and permissions on laravel 5.4. When we finish we will have a starter kit which we can use for our any future project which needs roles and permissions based access control.

http://www.qcode.in/easy-roles-and-permissions-in-laravel-5-4

Read more

A Laravel package to impersonate users

A great feature of Laravel Spark is it's ability to impersonate other users. As an admin you can view all screens as if you are logged in as another user. This allows you to easily spot a problem that your user might be reporting. Laravel-impersonate is a package, made by MarceauKa and Thibault Chazottes that can add this behaviour to any Laravel app.

Here are some code examples taken from the readme.

Auth::user()->impersonate($otherUser); // You're now logged as the $otherUser.

Auth::user()->leaveImpersonation(); // You're now logged as your original user.

$manager = app('impersonate');

// Find an user by its ID
$manager->findUserById($id);

// TRUE if your are impersonating an user.
$manager->isImpersonating();

// Impersonate an user. Pass the original user and the user you want to impersonate
$manager->take($from, $to);

// Leave current impersonation
$manager->leave();

// Get the impersonator ID
$manager->getImpersonatorId();

It even includes some handy blade directives:

@canImpersonate
    <a href="{{ route('impersonate', $user->id) }}">Impersonate this user</a>
@endCanImpersonate

@impersonating
    <a href="{{ route('impersonate.leave') }}">Leave impersonation</a>
@endImpersonating

Want to know more, take a look at the package on GitHub.

Read more

Sending a welcome mail with Laravel 5.3

by Freek Van der Herten – 7 minute read

Recently I was working an a project where, in order to use the webapp, users should first apply for an account. Potential users can fill in request form. After the request is approved by an admin they may use the app. Our client expected that the barrier to request an account should be very low.…

Read more

Learn about grant types in Laravel Passport

Laravel Passport is an easy to use OAuth2 server that was released alongside Laravel 5.3. Mohamed Said wrote an excellent guest post at Laravel News about the grant types used in Passport.

OAuth2 is a security framework that controls access to protected areas of an application, and it’s mainly used to control how different clients consume an API ensuring they have the proper permissions to access the requested resources.

Laravel Passport is a full OAuth2 server implementation; it was built to make it easy to apply authentication over an API for laravel-based web applications.

https://laravel-news.com/2016/08/passport-grant-types/

Read more

Improvements to Authentication in Laravel 5.3

In my book Joseph Silber is one of the unsung heroes of the Laravel ecosystem. Whenever I open up internals on Larachat or Github he's giving friendly and thoughtful advice. I was happy to learn that Joseph started a blog.

In the first post he goes over all the improvements made to authentication in Laravel 5.3.

Authentication has gotten some nice improvements in 5.3, so let's examine it piece by piece.
  • Introducing the authenticate method
  • The exception handler's unauthenticated method
  • The Authenticate middleware
  • Authenticating against multiple guards
  • Route model binding and global scopes
  • Bonus: the request's expectsJson method

https://josephsilber.com/posts/2016/07/10/authentication-improvements-in-laravel-5-3

If you're looking for a package that can handle roles and abilities in Laravel, be sure to check out his Bouncer package.

Read more

Using Github authentication for login with Laravel Socialite

Laravel hero Matt Stauffer has a new article on his blog where he talks about using a social network site login as the primary login for your application.

Laravel's Socialite package makes it simple to authenticate your users to Facebook, Twitter, Google, LinkedIn, GitHub and Bitbucket. You can authenticate them for the purpose of connecting their pre-existing user account to a third-party service, but you can also use it as your primary login mechanism, which we'll be talking about here.

I'm working on a new little micro-SaaS that is purely dependent on GitHub in order to operate, so there's no reason to set up any user flow other than just GitHub. Let's do it.

https://mattstauffer.co/blog/using-github-authentication-for-login-with-laravel-socialite

Read more

API Token Authentication in Laravel 5.2

Typically my applications have a UI and authentication is done through a simple login page. Obviously for a RESTful API, having a login page isn't ideal. Instead, my hope was to have users append an api_token to the end of their query string and use that to authenticate their request. I was happy to find that 5.2 also ships with a TokenGuardlink class that allows you to do exactly that, but the documentation on getting it to work was a bit thin, so here you go.
https://gistlog.co/JacobBennett/090369fbab0b31130b51

Read more

Introducing Laravel Spark

Matt Stauffer wrote another excellent article on Laravel. This time he gives a tour of Laravel Spark.

In case you're still having a bit of trouble understanding what Spark is really about, Spark is a tool designed to make it quicker for you to spin up SaaS applications, and it handles user authentications, plans and payments and coupons, and team logic.

Most SaaSes have these same components: user accounts, Stripe-based payments, and different payment plans. And many have payment coupons and team payment options.

Rather than re-creating this functionality with every new Laravel app you create, just use Spark, and you'll get all that and a free SaaS landing page to boot.

https://mattstauffer.co/blog/introducing-laravel-spark-a-deep-dive

Read more