Do you need to build your own auth for apps? | Logto docs (2024)

Prologue

Although article is inspired from personal dev experience and I tried my best to keep things objective, it's still non-negligible that I'm one of the creators of Logto (an auth product).

I would like to point out this first for a better reading experience.

I’ve seen a lot of developers asking questions like “Should I build my own auth for my app?”. While the answer cannot be a simple "Yes" or "No", I’d like to write an article to breakdown the implementation and demonstrate the pros and cons to help you decide.

TL;DR If you're still learning, auth will be a good challenge. If you want full control, it's worth building your own auth system. Otherwise, it's necessary to find an existing solution that fits your needs.

Intro

As a developer, I have built many applications during my career. Regardless of the programming language, there is a common foundation I always need to construct: user auth.

It was a negligible part since everything was straightforward going back to 20 years ago:

  • Implement a registration and sign-in system with username and password.
  • Create a mechanism to maintain a user's session.
  • About security? MD5 is the answer.

That’s it. Then I could focus on “the real business”. Didn't hear about MD5? You missed out on the "good times" of software development. Nowadays, developers face more challenges when building sign-in/up.

It sounds alarmist, but let me go through with an example.

Example: An online bookstore

Let’s say you are trying to build an online bookstore with an API service and a web frontend app.

First, the scope of “auth” should be defined. Auth can be explained as authentication and authorization, and they have totally different definitions and use cases:

🤔 About Auth

  • Authentication (AuthN) answers the question “Which identity do you own?”
  • Authorization (AuthZ) answers the question “What can you do?”

I wrote an article CIAM 101: Authentication, Identity, SSO to discuss these concepts in detail.

Choose authentication methods

Let’s start with “authentication”, which is user sign-in in our example. Besides the username-and-password method, here are some trending methods people are adopting for a better user conversion and security:

  • Passwordless, i.e. dynamic verification code (via email or sms)
  • Social sign-in (Google, Facebook, etc.)

The choice of method depends on the business decision, while we can take a look on the tech effort:

  • For passwordless, you need to find a vendor to send verification codes via email or sms; then integrate with your API service (new APIs may needed).
  • For social sign-in, you must adhere to the integration guidelines of the social identity provider(s) you wish to use. Additionally, you must create a mapping between your bookstore's user IDs and the identity provider's.
    • For example, when a user signs in with a Gmail account [emailprotected], you can link this email address to the user foo in the bookstore. This process helps you to build a unified identity system and allows the user to modify or unlink their social identity in the future.

Design and implement sign-in experience

After you decide authentication methods, a graceful and smooth sign-in experience for your end-users is the next target. The conversion here is fundamental but crucial to the business since it's a natural way to leave the persisted customer data.

When I was working for Airbnb, there was a whole team dedicated to optimize the sign-in experience for multiple platforms. They conducted numerous A/B tests to determine which combination had the highest conversion rate.

It’s not practical to do so when a business is getting started. But we still need to try our best to make every piece right. Which platforms would you like to run the bookstore? You may start with mobile, web, or both. The exact design will depend on the authentication methods you choose:

  • Username and password: The easiest one, just several input boxes and buttons.
  • Passwordless: Enter phone / email, then send and verify a dynamic code.
  • Social sign-in: Read the docs from the chosen social identity provider, follow the visual guideline, handle the redirect logic, and finally link the social identity with the bookstore identity.

More things to consider to make it better:

  • Do you need to combine the sign-in and registration process for a specific method?
  • Do you need a “forgot password” flow to allow customers to reset their passwords independently?

If you opt for native development, the workload will almost double for one additional platform.

Security and token exchange

Security can be a hidden iceberg. It’ll be great if you are familiar with OpenID Connect or OAuth 2.0, since they are widely used and battle-tested. OpenID Connect is relatively new but is designed for “user authentication”, which is a great fit for an online bookstore.

Without delving into the details of the standards, there are still some things to consider:

  • Which encryption method should be used for passwords?
  • What is the process for standard authentication and authorization?
  • How does token exchange work (Access Token, Refresh Token, ID Token, etc.)?
  • How can signing keys be used in tokens and how can the signature be validated to protect resources?
  • How can client and server attacks be prevented?

Finally, you can land a good sign-in experience and deliver it to your customers.

Authorization model

As a bookstore, you need to separate resources for customers and sellers. For example, customers can browse all books, while sellers can manage their on-sale books. It's OK to start with simple if-else checks; however, as the business grows, you may need to leverage a more flexible model such as Role-based Access Control (RBAC) or Attribute-based Access Control (ABAC).

I also wrote an article to demonstrate basic authorization concepts and the RBAC model.

Make the decision

You can see auth is not an “all or nothing” problem, since it involves multiple technical components and you or your team may have different tech expertise in these areas. It's important to break it down into smaller parts to gain a better understanding of the status quo.

To make the decision, I'll ask myself the following questions:

  • How urgent is the project?
  • How much effort do I expect to put into auth versus the business?
  • What’s the priority of user experience, security, and maintainability?
  • Which part(s) do I need full control of? How familiar should I become with them?
  • If I go with some frameworks / solutions, are they good enough for customization or extension?
  • If the business grows, will I need to introduce a new authentication model?
  • If I find a suitable vendor, is it safe enough to use? Do I need a withdrawal plan if anything happens to the vendor?

info

On the other hand, if you're still learning or honing your programming skills, auth can be a great stepping stone on the path to becoming a full-stack developer. It covers almost all components needed for an app.

With the questions in mind, I discovered two facts:

  • Crafting a reliable authentication system is highly complex.
  • Existing vendors cannot meet all the necessary criteria.

So I decided to start a dedicated project (Logto) for auth, and embrace the open-source community from day one.

Hope this article helps.

Do you need to build your own auth for apps? | Logto docs (2024)

FAQs

Do you need to build your own auth for apps? | Logto docs? ›

If you want full control, it's worth building your own auth system. Otherwise, it's necessary to find an existing solution that fits your needs.

Should I build my own auth system? ›

Control and Customization: Building your own authentication system offers greater control over the implementation, allowing customization to meet specific security and business requirements. Security Considerations: Backend developers often need to ensure high security standards.

Why do we need authentication for apps? ›

Authentication involves verifying the identity of an individual or system to ensure that they are who they claim to be. Authorization and authentication work together to provide a secure environment for protecting data, ensuring that only authorized individuals can access it.

How to implement auth? ›

How do I implement user authentication and authorization features in my web application?
  1. Choose an authentication method. ...
  2. Set up a user database. ...
  3. Create registration and login forms. ...
  4. Implement authentication logic. ...
  5. Include authorization logic. ...
  6. Use security measures.

Why use an auth provider? ›

Using an Authentication Service Provider abstracts the complexity of implementing the auth system yourself. Building such a system is a complex, lengthy process requiring many resources. You can use an existing solution that frees up those resources for other, more critical tasks.

Should I build my own API? ›

You Should Probably Build an API If:
  1. You want to build a mobile app or desktop app someday.
  2. You want to use modern front-end frameworks like React or Angular.
  3. You have a data-heavy website that you need to run quickly and load data without a complete refresh.

What is better than basic auth? ›

Modern authentication is a stronger method of identity management that provides more secure user authentication and access authorization. It allows a user access from a client device like a laptop or a mobile device to a server to obtain data or information.

How to create basic auth? ›

Basic authentication is a very simple authentication scheme that is built into the HTTP protocol. The client sends HTTP requests with the Authorization header that contains the Basic word followed by a space and a base64-encoded username:password string.

How do I implement authenticator app? ›

Steps To Set Up an Authenticator App
  1. Choose your authenticator app. We recommend using a password manager, but you have a few different options to choose from. ...
  2. Download the application to your device. ...
  3. Request a QR code from your account. ...
  4. Scan the QR code with the authenticator app. ...
  5. You're ready to go!
Jul 20, 2023

What is the purpose of auth? ›

Authentication (AuthN) is a process that verifies that someone or something is who they say they are. Technology systems typically use some form of authentication to secure access to an application or its data.

What is the difference between authentication and auth? ›

Simply put, authentication is the process of verifying who someone is, whereas authorization is the process of verifying what specific applications, files, and data a user has access to. The situation is like that of an airline that needs to determine which people can come on board.

Which authentication service is best? ›

  • Best for Privacy and Backups. 2FAS. 2FAS is a simple but fully functional app that does everything you want in an authenticator. ...
  • Best for Android. Aegis Authenticator. ...
  • Best for Workforces. Duo Mobile. ...
  • Best for Backup to Google Drive. Google Authenticator. ...
  • Best for Microsoft Accounts. Microsoft Authenticator.

How insecure is basic auth? ›

Basic authentication only obfuscates usernames and passwords in Base64 encoding, which can be easily recognized and reversed, thus it must not be transmitted over the cleartext HTTP channel. Transmitting sensitive information without using HTTPS makes the data vulnerable to packet sniffing.

What's a benefit of using OAuth instead of your own basic authentication? ›

When you compare both methods of authentication, OAuth 2.0 provides better security than basic authentication because its initial requests for credentials are made under the SSL protocol and its access object is a transitory token.

What are the disadvantages of basic authentication? ›

Problems with Basic Authentication
  • The username and password are sent in every request. ...
  • Most configurations of Basic Authentication do not implement protection against password brute forcing. ...
  • Logout functionality is not supported. ...
  • Passwords cannot be easily reset.

Which is the most powerful authentication method? ›

Categories
  • The Three Types of Authentication Factors.
  • Least Secure: Passwords.
  • More Secure: One-time Passwords.
  • More Secure: Biometrics.
  • Most Secure: Hardware Keys.
  • Most Secure: Device Authentication and Trust Factors.
Sep 4, 2024

Top Articles
What happened to the piggy bank? | Fandom
How To Know What To Expect When Selling Your Old Jewelry?
Craigslist San Francisco Bay
Thor Majestic 23A Floor Plan
Hotels
Lighthouse Diner Taylorsville Menu
Vaya Timeclock
Culver's Flavor Of The Day Wilson Nc
Polyhaven Hdri
Mohawkind Docagent
Bloxburg Image Ids
Jesus Revolution Showtimes Near Chisholm Trail 8
Progressbook Brunswick
Raid Guides - Hardstuck
Items/Tm/Hm cheats for Pokemon FireRed on GBA
Rosemary Beach, Panama City Beach, FL Real Estate & Homes for Sale | realtor.com®
Drago Funeral Home & Cremation Services Obituaries
Shreveport Active 911
978-0137606801
Sony E 18-200mm F3.5-6.3 OSS LE Review
Gon Deer Forum
Youravon Comcom
Webcentral Cuny
Vintage Stock Edmond Ok
Td Small Business Banking Login
Pickswise Review 2024: Is Pickswise a Trusted Tipster?
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Kohls Lufkin Tx
Foodsmart Jonesboro Ar Weekly Ad
Craigslist Fort Smith Ar Personals
Pioneer Library Overdrive
County Cricket Championship, day one - scores, radio commentary & live text
Fairwinds Shred Fest 2023
Bee And Willow Bar Cart
Frcp 47
Rochester Ny Missed Connections
Tiny Pains When Giving Blood Nyt Crossword
All Characters in Omega Strikers
Umd Men's Basketball Duluth
Wilson Tire And Auto Service Gambrills Photos
Advance Auto.parts Near Me
Graduation Requirements
40X100 Barndominium Floor Plans With Shop
Fresno Craglist
Wild Fork Foods Login
Sleep Outfitters Springhurst
Dmv Kiosk Bakersfield
Parks And Rec Fantasy Football Names
Edict Of Force Poe
Att Corporate Store Location
Qvc Com Blogs
Latest Posts
Article information

Author: Trent Wehner

Last Updated:

Views: 6395

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Trent Wehner

Birthday: 1993-03-14

Address: 872 Kevin Squares, New Codyville, AK 01785-0416

Phone: +18698800304764

Job: Senior Farming Developer

Hobby: Paintball, Calligraphy, Hunting, Flying disc, Lapidary, Rafting, Inline skating

Introduction: My name is Trent Wehner, I am a talented, brainy, zealous, light, funny, gleaming, attractive person who loves writing and wants to share my knowledge and understanding with you.