Liferay Authentication with OAuth2 — Complete Guide

 Modern applications rarely authenticate users directly.

They delegate authentication to trusted identity providers like Google, Azure AD, or Keycloak using OAuth2.

In Liferay, OAuth2 allows secure Single Sign-On (SSO) across microservices and external apps.

This guide explains how OAuth2 works in Liferay and how to configure it.


📌 What is OAuth2 in Liferay?

OAuth2 enables:

  • External login (Google / Azure / IdP)

  • Secure API access

  • Token-based authentication

  • Decoupled frontend & backend

Instead of sending passwords → apps exchange access tokens.


🖼️ OAuth2 Authentication Flow


🧠 OAuth2 Roles

RoleDescription
Resource OwnerUser
ClientLiferay
Authorization ServerIdentity Provider
Resource ServerAPIs

🛠 Step 1 — Enable OAuth2 in Liferay

Go to:

Control PanelSecurityOAuth2 Administration

Create a new OAuth2 Application.


🛠 Step 2 — Configure Client

Fill:

  • Name

  • Client ID

  • Client Secret

  • Redirect URI

Example:

http://localhost:8080/c/portal/oauth2/redirect

🖼️ OAuth2 Configuration


🛠 Step 3 — Configure Identity Provider

Example Keycloak:

Valid Redirect URI: http://localhost:8080/*

Scopes:

openid profile email

🛠 Step 4 — Map User Attributes

Map IdP fields → Liferay user:

IdP FieldLiferay
emailemailAddress
given_namefirstName
family_namelastName

🧠 Step 5 — Access Token Usage

After login Liferay receives:

access_token refresh_token id_token

Use token in APIs:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

🖼️ Token Example


⚠️ Common Issues

Invalid redirect URI

Must match exactly

User not created

Attribute mapping missing

Login loop

Clock difference between servers

Token rejected

Wrong audience / scope


🔐 Security Best Practices

✔ Use HTTPS only
✔ Short token expiry
✔ Use refresh tokens
✔ Restrict scopes
✔ Sync server time (NTP)


📚 Related Articles

These help build secure enterprise architectures.


🎯 Conclusion

OAuth2 integration makes Liferay enterprise-ready:

  • Centralized authentication

  • Secure APIs

  • Scalable microservices access

Once configured correctly, users can log in seamlessly across all connected applications.


💼 Professional Support Available

If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.

Technologies covered include Java, Spring Boot, PL/SQL, CMS, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).


🎥 Learn IT with Shikha on YouTube

Prefer learning through videos? Watch practical tutorials on Kafka, Camunda, Alfresco, Java, Spring Boot, Microservices and Enterprise Architecture.

▶ Subscribe to Learn IT with Shikha on YouTube

Comments

Popular posts from this blog

Top 50 Camunda BPM Interview Questions and Answers for Developers (2026 Guide)

10 BPMN Best Practices Every Camunda Developer Should Know

OOPs Concepts in Java | English | Object Oriented Programming Explained