OAuth 401 error when using server-to-server auth in AEM

A 401 Unauthorized error in AEM as a Cloud Service can occur when switching from JWT to OAuth server-to-server authentication. This article explains how to fix it by verifying OAuth credentials, token validity, and endpoint configuration.

Description description

Environment

Adobe Experience Manager as a Cloud Service (AEMaaCS) - Sites

Issue/Symptoms

When using an OAuth 2.0 access token generated via the client credentials flow to access an AEM Cloud URL, the request fails with a 401 Unauthorized error. This typically occurs during the transition from JWT-based authentication to OAuth server-to-server authentication.

Resolution resolution

To resolve the 401 Unauthorized error when using OAuth Server-to-Server authentication for AEM, follow these steps:

  1. Ensure that the client ID and secret in your request are correct, and that the OAuth credentials have the right scopes configured in the Adobe Developer Console.
  2. Check that the access token is generated properly and hasn’t expired. If needed, generate a new token.
  3. Confirm you’re using the correct API endpoint for your AEM instance.
  4. Add the authorization header in your HTTP request like this: Authorization: Bearer <access_token>.
  5. Review any security settings such as IP whitelisting or firewall rules that might block your request.
  6. If you’re still using Adobe Developer Console, consider switching to AEM Developer Console. It supports both JWT and OAuth and comes pre-configured with IMS Client integration.
  7. Enable logging for your HTTP requests to capture request headers and responses. This helps with debugging.

For more help, check Adobe’s official documentation on access token generation and server-to-server authentication setup.

recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f