You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This RFC proposes a simple yet effective authentication solution for headless WordPress implementations using FaustWP Toolkit. The goal is to establish secure, flexible, and developer-friendly authentication mechanisms that work seamlessly in a decoupled WordPress architectures.
Background
Headless WordPress architectures present unique authentication challenges that differ from traditional WordPress implementations. In a traditional WordPress setup, authentication is handled through cookies and sessions, with WordPress managing the entire user experience.
However, in a headless architecture:
The frontend application is decoupled from WordPress, typically running on a different domain
Traditional cookie-based authentication becomes problematic due to CORS restrictions
Server-side rendering (SSR) requires different authentication approaches than client-side rendering.
WordPress's native authentication mechanisms aren't designed for headless architectures.
The current state of authentication in headless WordPress implementations often involves custom solutions, leading to:
Inconsistent security practices via custom authentication implementations.
Poor developer experience. No modularity
Limited support for modern authentication standards since they are harder to maintain.
Difficulty implementing features like password reset and social login since this requires federation and other features that are very custom-made.
Proposal
We propose creating a flexible authentication framework for FaustWP that supports multiple authentication providers, with WPGraphQL Headless Login (https://github.com/AxeWP/wp-graphql-headless-login) serving as the recommended plugin. However, developers could also use a compatible plugin that followers similar principles and feature sets without any obstructions.
Abandoned Ideas (Optional)
NA
Documentation and Examples
Basic Authentication Flow - Fetch API
import{LOGIN_MUTATION}from'./#.queries.graphql';constlogin=async(username: string,password: string)=>{try{constresponse=awaitfetch(process.env.NEXT_PUBLIC_WORDPRESS_API_URL!,{method: "POST",headers: {"Content-Type": "application/json"},body: JSON.stringify({query: LOGIN_MUTATION,variables: { username, password },}),});const{ data }=awaitresponse.json();if(data.errors){thrownewError(data.errors[0]?.message||"Authentication failed");}const{ user, ...tokens}=data.login;// Update statestorage.setItem("authTokens",JSON.stringify(tokens));storage.setItem("user",JSON.stringify(user));setAuthState({
user,
tokens,isLoading: false,});// Navigate to protected dashboard pagenavigation.push("/dashboard");returndata.login;}catch(error){console.error("Error during login:",error);throwerror;}};
Basic Authentication Flow - Apollo
import{LOGIN_MUTATION}from'./#.queries.graphql';// Assume apollo client was configuredconst[loginMutation]=useMutation(LOGIN_MUTATION);constlogin=async(username: string,password: string)=>{try{const{ data }=awaitloginMutation({variables: { username, password },});if(!data?.login){thrownewError('Login failed');}const{ user, ...tokens}=data.login;// Update statestorage.setItem('authTokens',JSON.stringify(tokens));storage.setItem('user',JSON.stringify(user));setAuthState({
user,
tokens,isLoading: false,});// Navigate to protected dashboard pagenavigation.push('/dashboard');returndata.login;}catch(error){console.error('Error during login:',error);throwerror;}};
Plugin Agnosticism
The authentication framework can remain plugin-agnostic while providing clear integration patterns. This is achieved through the following suggestions:
WordPress application passwords can be used for authenticating API requests, including WPGraphQL queries, without exposing user passwords. This is useful for:
Automated scripts interacting with WPGraphQL.
Backend services that require API access.
Secure authentication for headless WordPress setups.
Example: Using Application Passwords for WPGraphQL Authentication
To authenticate using an application password, a user must have an account with an application password created. The credentials are then used in a Basic authentication header:
topic:authRelated to Authentication or Authorization
1 participant
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Status: WIP
Current Version: 0.1.0
Owner: TBD
Target Version: 1.0.0
Contributors: TBD
PRD: N/A
This RFC proposes a simple yet effective authentication solution for headless WordPress implementations using FaustWP Toolkit. The goal is to establish secure, flexible, and developer-friendly authentication mechanisms that work seamlessly in a decoupled WordPress architectures.
Background
Headless WordPress architectures present unique authentication challenges that differ from traditional WordPress implementations. In a traditional WordPress setup, authentication is handled through cookies and sessions, with WordPress managing the entire user experience.
However, in a headless architecture:
The current state of authentication in headless WordPress implementations often involves custom solutions, leading to:
Proposal
We propose creating a flexible authentication framework for FaustWP that supports multiple authentication providers, with WPGraphQL Headless Login (https://github.com/AxeWP/wp-graphql-headless-login) serving as the recommended plugin. However, developers could also use a compatible plugin that followers similar principles and feature sets without any obstructions.
Abandoned Ideas (Optional)
NA
Documentation and Examples
Basic Authentication Flow - Fetch API
Basic Authentication Flow - Apollo
Plugin Agnosticism
The authentication framework can remain plugin-agnostic while providing clear integration patterns. This is achieved through the following suggestions:
Interface Definitions
Local storage integration
Next.js integration
Application Passwords
WordPress application passwords can be used for authenticating API requests, including WPGraphQL queries, without exposing user passwords. This is useful for:
Example: Using Application Passwords for WPGraphQL Authentication
To authenticate using an application password, a user must have an account with an application password created. The credentials are then used in a Basic authentication header:
This could be used for
graphql-codegen
to download the schema at build time over HTTPS.Starter Templates / scripts
We will need to provide the following artifacts as part of the example projects:
Beta Was this translation helpful? Give feedback.
All reactions