API Authentication & Authorization using Passport.js

Want to secure your angular application? Want to ensure that the APIs are protected and only authorized persons are able to use the application? Passport.js can help you with that.

Passport.js is a flexible authentication middleware for your node.js APIs/ Application. Passport.js offers different mechanisms for authorization known as strategies. There are more than 400 strategies that support authentication using multiple ways like login with username and password, on single sign-ons using OAuth providers like Facebook, Twitter, and many more.

These strategies are packaged in different modules, which the user can choose as per application needs and install the required ones without adding multiple unnecessary dependencies.

Here are a few strategies of passport.js:

Local Strategy: When a user tries to log on to a web application, a POST request will be made resulting in passport.js local strategy execution. The authentication middleware for the login route will use our passport-local strategy to verify the username and password within the database entries. Accordingly, the errors or success messages will be given to the user. If the user login is successful, the user will be led to the appropriate home page.

Custom Strategy: You can write your own code for user verification for authentication using passport-custom strategy. It is based on the passport-local module developed by Jared Hanson.

OAuth: The OAuth 2.0 Strategy authenticates a user using a third-party account and OAuth 2.0 tokens. OAuth is standard protocol used to allow authorized access to API applications. This strategy requires a verify call-back function with access token and profile.

Facebook: This strategy helps you to authorize your application using Facebook account and OAuth 2.0 tokens. To integrate passport-Facebook strategy in your application, you need to register your application with Facebook. Once registered, the app ID and app secret is issued, and it has to be integrated into your application along with the call-back URL.

Twitter: The passport strategy to authenticate a user  with a Twitter account and OAuth tokens. Your application must be registered with Twitter. Then the consumer key and consumer secrets are issued for application, which are used while integrating this strategy. Also, call-back URL for your application should be configured. This strategy also uses verify call-back function with consumer-secret, access-token, and Twitter user profile as arguments.

Looking for API services? 

 
Share:

Related Posts

Voice User Interface

Exploring Voice User Interface (VUIs)

Voice user interface (VUI) is one of the key design trends in 2022. VUI is used for allowing the users to interact with the system through voice…

Share:
6 Challenges In Going Cloud-Native - And The Perfect Solution

6 Challenges In Going Cloud-Native – And The Perfect Solution

Going cloud-native carries with it a number of challenges, but danger, properly harnessed, becomes opportunity. Check out this article to see what obstacles lie in your path – click here!

Share:
Hybrid Digital Infrastructure - An Analysis

Hybrid Digital Infrastructure: An Analysis

Keeping your digital infrastructure completely on-prem or completely cloud-based offers several advantages and disadvantages, but companies have started adopting the hybrid model for more flexibility. We analyze this new trend here – read on for more.

Share:
Cloud Native

What CTOs must know about Infrastructure as a Service

The benefits of IaaS are many, but using that tech correctly requires careful analysis. This article explores the factors that CTOs should be paying attention to.

Share:

[Infographics] What is the state of the Cloud in 2022?

In this infographic, we give an overview of the condition of the Cloud Industry, and take a look at the changes the past few years have caused.

Share:

User Experience For All

A Product, a Service, or Content which is fully Accessible & Usable by its users with the widest possible range of abilities & situations across all streams & ages and is built around a human-centered philosophy that recognizes diversity, embracing the difference is something termed as Best User Experience. It is about making things accessible to individuals (whether they have a disability or not).

Share: