Using Liferay as a Headless Platform

Using OAuth 2.0

OAuth 2.0 is an industry-standard authorization protocol. Users with accounts on a Liferay-based website can share select credentials with various clients seamlessly. OAuth 2.0 works by authorizing password-less access to portions of user-owned resources (such as an email address, a user profile picture, or something else from your account) and other permissioned resources. OAuth 2.0’s design encrypts all authorization transport through HTTPS, which prevents data passed between the systems from being intercepted.

You can jump into creating OAuth 2.0 apps or continue reading to learn how it works.

  1. Creating an OAuth 2.0 Application
  2. Defining Scopes
  3. Authorizing Account Access

Flow of OAuth 2.0

OAuth 2.0 takes advantage of web standards wherever possible: transport is encrypted with HTTPS; tokens are implemented as HTTP headers; data is passed via web services.

Here’s how OAuth 2.0 works:

OAuth 2.0 takes advantage of web standards.

  1. A user accesses a third-party application that supports authorization via credentials from a Liferay-based website. In the application (web or mobile), the user requests authorization via OAuth, sending the browser or app to the Liferay-based website. When using the Proof Key for Code Exchange or PKCE flow (explained below), the application also generates a code verifier and sends a code challenge that is created by applying a transformation to it.

  2. The user authenticates and is shown the resources the application wants permission to access. When the user gives permission by clicking Allow, Liferay generates an authorization code that’s sent to the application over HTTPS.

  3. The application then requests a more permanent access token and sends the code with the request (along with the PKCE code verifier).

    Note

    If requesting a token on the same instance, Liferay produces no network traffic.

  4. If the authorization code matches (and the transformed PKCE code verifier matches the previously sent code challenge), Liferay cryptographically generates an access token for this user and application combination. It sends the token to the application over HTTPS. Initial authorization is now complete!

  5. When the application must retrieve data, it sends the token with the request to prove it’s authorized to have that data.

  6. Provided the token matches what Liferay has for that user and application, access is granted to retrieve the data.

That description throws around a lot of terms. Definitions provided below.

Important

A user must have these two permissions to generate and view access tokens:

  • Control Panel → Security → OAuth 2 Administration - OAuth 2 Application Entry → Create Token
  • Control Panel → Security → OAuth 2 Administration - OAuth 2 Application Entry → View

OAuth 2.0 Terminology

Authentication: Providing credentials so a system can verify who you are by matching those credentials with what it has stored. OAuth is not an authentication protocol.

Authorization: Granting access to resources stored on another system. OAuth is an authorization protocol.

Application: Any client (web, mobile, etc.) that must be authorized to have access to resources. Applications must be registered by administrators before users can authorize access to their resources.

Client: Almost synonymous with application except that applications can have variants, such as web and mobile. These variants are clients.

Client ID: An identifier given to a client so it can be recognized.

Client Secret: A previously agreed-upon text string that identifies a client as a legitimate client.

Access Token: A cryptographically generated text string that identifies a user/client combination for access to that User’s resources.

Response Type: OAuth 2.0 supports several response types. Pictured and described above is the most common: the authorization code. Other response types are password (logging in with a user name and password), and client credentials (headless predefined application access).

Scope: A list of items that define what the application wants to access. This list is sent during the initial authorization request (or otherwise defaults to scopes selected in the application registration) so users can grant or deny access to their resources.

Callback URI: Also called a Redirection Endpoint URI. After authorization is complete, the authorization server (i.e., Liferay) sends the client to this location.

Technical Standards and Specifications

Liferay DXP implements OAuth 2.0 in the roles of Authorization Server and Resource Server, as defined by the OAuth 2.0 specifications. Compliance statements in this section apply only to these roles.

Liferay implements specifications published by the OAuth working group to promote interoperability and reduce vendor lock-in. While vendor-specific extensions may exist in certain DXP versions, Liferay addresses these requirements through external solutions rather than customizing Liferay DXP itself. Features that extend or adapt these specifications fall outside the scope of formal OAuth 2.0 compliance claims.

In the specifications listed below, the keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” are interpreted as described in RFC 2119.

For the OAuth 2.0 roles implemented by Liferay DXP, requirements marked as MUST (and equivalent terms) in the specifications are implemented and supported. Support for requirements marked as SHOULD or MAY varies by DXP version.

SpecificationDescriptionImplemented in Liferay DXPLink
OAuth 2.0 Authorization Framework (RFC 6749)Defines OAuth roles, authorization flows, tokens, and scopes.All MUST requirements for supported roles are implemented.https://datatracker.ietf.org/doc/html/rfc6749
Proof Key for Code Exchange (PKCE, RFC 7636)Defines protections for the Authorization Code flow against interception attacks.Supported for the Authorization Code flow.https://datatracker.ietf.org/doc/html/rfc7636
Bearer Token Usage (RFC 6750)Specifies how bearer tokens are used to access protected resources.All MUST requirements are implemented.https://datatracker.ietf.org/doc/html/rfc6750
OAuth 2.0 Token Introspection (RFC 7662)Defines a mechanism for resource servers to query token state.Supported where applicable.https://datatracker.ietf.org/doc/html/rfc7662
OAuth 2.0 Threat Model and Security Considerations (RFC 6819)Specifies security threats and recommended mitigations.Security recommendations are applied where relevant.https://datatracker.ietf.org/doc/html/rfc6819
JWT Bearer Token Authorization Grant (RFC 7523)Defines a JWT-based authorization grant for system integration.Supported where applicable.https://datatracker.ietf.org/doc/html/rfc7523
JWT Profile for OAuth 2.0 Access Tokens (RFC 9068)Defines a standard JWT-based access token format.Supported where applicable.https://datatracker.ietf.org/doc/html/rfc9068

Next Steps