Restrict page-access with CDN-level OIDC authentication
Learn how to restrict access to a section of any Edge Delivery Services site, regardless of authoring source, with CDN-level OpenID Connect (OIDC) authentication, using Google as the example identity provider.
This works for any Edge Delivery Services site, whatever the content source: AEM Author with Universal Editor (crosswalk), Document Authoring (DA), or any other source. The CDN only sees requests and URL paths, so it does not matter how the content was authored.
This tutorial uses Google as the identity provider (IdP) to demonstrate the steps. The same concepts apply to any standards-compliant OIDC IdP, such as Microsoft Entra ID or Okta. Only the IdP-specific parts differ: creating the client in Step 2 and the endpoint values in Step 4.
CDN-level OIDC authentication does NOT support user groups. The CDN only checks that a visitor signed in successfully, so you CANNOT allow or deny access based on group membership.
What you build
In this tutorial, you add a members-only section, the Frescopa Insiders Lounge, to the demo Frescopa Edge Delivery Services site served from dev-myfrescopa.enablementadobe.com.
Everything under /members/ requires a Google sign-in. The rest of the site stays public.
/ and all other pages/members/welcome/signed-out/login, /callback, /logoutoidc branch of the Dev site, so they are served under the /dev/branches/oidc prefix, for example /dev/branches/oidc/members/welcome. The CDN configuration in Step 4 accounts for this prefix.How it works
- A visitor requests the protected
/members/welcomepage. - The CDN rule matches the
/members/path and finds no valid session using the_aem_oidc_session_tokencookie, so it redirects the visitor to Google to sign in. - After sign-in, Google sends the visitor back to the Adobe-managed CDN
callbackURL. The CDN verifies the returned token against Google’s public keys (jwksUri) andissuer. It then creates a session and sets the_aem_oidc_session_tokencookie for subsequent requests. - The CDN serves the requested
/members/welcomepage to the visitor, now that a valid session exists.
How the CDN trusts the token
The token Google returns in step 3 is a digitally signed ID token. Google signs it with a private key that only Google holds, and publishes the matching public keys at the jwksUri address. The CDN trusts the token only after two checks:
- Signature: The CDN retrieves the public keys from
jwksUriand uses them to confirm that the token was signed by Google and was not altered on the way back. A token that someone forged or edited fails this check. - Issuer: The token states who issued it. The CDN confirms that this matches the configured
issuer, so a validly signed token from a different identity provider is rejected.
Only after both checks pass does the CDN create the session and set the _aem_oidc_session_token cookie. On later requests, the CDN checks this cookie instead of sending the visitor to Google again, so no round trip to Google is needed for each page.
The sign-in is enforced at the Adobe-managed CDN only. The same content is also reachable on the .aem.live hostname, so restrict access there as well to ensure that only authenticated visitors can reach your content. See Step 6: Restrict access to the .aem.live origin.
Prerequisites
To follow this tutorial, you need to have the following prerequisites in place:
- Your program is enrolled in the CDN-level OIDC authentication beta.
- The Frescopa site (or your own Edge Delivery Services site) is set up in Cloud Manager and served from a custom domain on the Adobe-managed CDN. See Step 1: Onboard your Edge Delivery site to Cloud Manager of Set up AEM Edge Functions on Edge Delivery Services for details.
- A Cloud Manager Edge Delivery configuration pipeline exists, and you can edit its variables. See Edge Delivery configuration pipeline.
- A Git repository connected to the pipeline that contains a
config/folder (the pipeline in this tutorial readsconfig/cdn.yaml). - A Google account that can create projects in Google Cloud Console.
- Access to the Frescopa content source to author and publish a page.
/members/ the way you normally do.Step 1: Create the members-only content
First, create the section or pages that the sign-in protects. For demonstration purposes, this tutorial uses a single members-only page called welcome under the members section.
-
Follow the branches page pattern to create the
memberssection and thewelcomepage within it. For example, the resulting path is/content/frescopa/en/dev/branches/oidc/members/welcome.
-
Author the
welcomepage with the following content:table 0-row-2 1-row-2 2-row-2 3-row-2 Section Content Hero Heading: Welcome to the Frescopa Insiders Lounge. Text: Early access to small-batch roasts, brewing masterclasses, and members-only offers. Cards (3) Roaster’s Reserve (this month’s limited lot with tasting notes), Brew like a barista (a guide to dialing in espresso at home), Insiders offers (a members-only discount code) Default content A line telling visitors how to leave: Done for the day? Sign out. The Sign out should point to /logoutURI to trigger the sign-out process.
-
Create a public page called
signed-outas a sibling of thememberssection, with a short message such as You have been signed out of the Frescopa Insiders Lounge and a link back to the home page.
-
Preview both pages and publish them.
signed-out page under the /members/ section. Otherwise, the visitor is redirected back to the Google sign-in immediately after signing out.At this point, /members/welcome is still publicly reachable. You protect it in the following steps.
Step 2: Create the Google OAuth client
For this setup, Google acts as the IdP. You need to create an OAuth client in the Google Cloud Console so that Google knows about your web application and where to send visitors after they sign in.
callback URL as its redirect URI, and use your IdP’s endpoints (from its OIDC discovery document) in Step 4. The rest of the tutorial stays the same.-
In Google Cloud Console, select or create a project, for example
frescopa-insiders.
-
Open APIs & Services > OAuth consent screen and configure the consent screen:
- Set the App name to
Frescopa Insiders Loungeand add your support email. - Select the User Type, either Internal (Google Workspace only) or External, according to your use case. This tutorial uses External.
- Keep the default scopes (
openid,email,profile).
- Set the App name to
-
Open Credentials > Create credentials > OAuth client ID.
- Set Application type to Web application and Name to
Frescopa Members Only. - Under Authorized redirect URIs, add the CDN callback URL:
https://dev-myfrescopa.enablementadobe.com/callback.
- Set Application type to Web application and Name to
-
Select Create and copy the Client ID and Client secret. You use them in the next steps.
callback setting exactly, including the scheme, domain, and path. In this tutorial, it is https://dev-myfrescopa.enablementadobe.com/callback. Use the domain of your own environment.- Internal (Google Workspace only): only users in your Workspace organization can sign in.
- External in Testing status: only the test users you list can sign in.
- External in In production status: any Google account can sign in. This suits identifying visitors, not restricting them.
Google endpoints used in the CDN configuration
Google publishes these values in its OpenID Connect discovery document. Use them in Step 4.
authEndpointhttps://accounts.google.com/o/oauth2/v2/authtokenEndpointhttps://oauth2.googleapis.com/tokenjwksUrihttps://www.googleapis.com/oauth2/v3/certsissuerhttps://accounts.google.comGoogle does not publish an end-session endpoint, so no logoutEndpoint is needed. Logout ends the CDN session by removing the _aem_oidc_session_token cookie only, and the visitor stays signed in to Google itself.
Step 3: Add secrets to the configuration pipeline
Next, you add the above client secret to the configuration pipeline so that it can be securely referenced in your CDN configuration.
-
In Cloud Manager, navigate to your Program > Edge Delivery > Pipelines section. Select the ellipsis (
...) next to the pipeline, then View/Edit variables.
-
Add the following variable, set its type to Secret, and apply it to the Deploy step:
table 0-row-2 1-row-2 Variable Value FRESCOPA_OIDC_CLIENT_SECRETThe Google client secret from Step 2
-
Select Save.
Step 4: Configure CDN-level OIDC authentication
Next, you configure CDN-level OIDC authentication by adding the authenticator to your config/cdn.yaml along with a rule that applies it to the /members/ path.
# config/cdn.yaml
kind: 'CDN'
version: '1'
data:
...
authentication:
authenticators:
- name: frescopa-google-oidc
type: oidc
clientId: "585724821762-xxxxxxxx.apps.googleusercontent.com"
clientSecret: ${{FRESCOPA_OIDC_CLIENT_SECRET}}
authEndpoint: "https://accounts.google.com/o/oauth2/v2/auth"
tokenEndpoint: "https://oauth2.googleapis.com/token"
jwksUri: "https://www.googleapis.com/oauth2/v3/certs"
issuer: "https://accounts.google.com"
domainMatch: "^dev-myfrescopa\\.enablementadobe\\.com$"
callback: /callback
login: /login
loginTarget: /dev/branches/oidc/members/welcome
logout: /logout
logoutTarget: /dev/branches/oidc/signed-out
rules:
- name: frescopa-members-rule
when:
allOf:
- { reqProperty: domain, equals: "dev-myfrescopa.enablementadobe.com" }
- { reqProperty: path, matches: "^(/dev/branches/[^/]+)?/members/.*" }
action:
type: authenticate
authenticator: frescopa-google-oidc
clientId, clientSecretauthEndpoint, tokenEndpoint, jwksUri, issuerdomainMatchcallback, login, and logout endpoints are active.callback, login, logoutcallback must equal the redirect URI you registered at Google.loginTargetlogoutTargetrulesoidc branch, the path regular expression, loginTarget, and logoutTarget include the /dev/branches/oidc prefix. On a production site, use ^/members/.*, /members/welcome, and /signed-out instead.domain condition in the rule. Without it, the rule applies to every domain served by the program, including other sites.If your Git repository already contains a config/cdn.yaml (for example, from the AEM Edge Functions tutorials), add the authentication block under the existing data instead of creating a second file. For example, see lines 18-43 of Frescopa’s cdn.yaml for the complete authentication block with the authenticator and the authenticate rule.
Finally, commit the change and push it to the branch that the configuration pipeline’s Source Code step uses.
Step 5: Deploy the configuration
Run the configuration pipeline to apply the changes.
-
In Cloud Manager, open the Edge Delivery > Pipelines section and verify that the configuration pipeline’s Source Code step points at the branch where you committed
cdn.yaml.
-
Run the configuration pipeline.
-
Monitor the pipeline until it completes successfully.
Step 6: Restrict access to the .aem.live origin
The CDN rule protects dev-myfrescopa.enablementadobe.com, but the same content is also served from the Edge Delivery Services origin hostname, https://<branch>--<site>--<org>.aem.live. Anyone who knows that address can read the protected pages and skip the sign-in.
.aem.live hostname so that the Adobe-managed CDN is the only way to reach your content.To do so:
- Enable site authentication for your Edge Delivery Services site. See Set up site authentication.
- Configure the Adobe-managed CDN to present the site authentication token on every request to the origin. See Origin Authentication in Adobe-managed CDN configuration.
This tutorial does not restrict the .aem.live hostname, so it can focus on the OIDC flow.
Step 7: Verify
Verify the sign-in flow in a browser.
-
In your browser, go to the Frescopa Insiders Lounge page. The URL is
https://dev-myfrescopa.enablementadobe.com/dev/branches/oidc/members/welcome. -
Confirm that you are redirected to the Google sign-in screen, and sign in with an account that your consent screen allows.
-
Confirm that you land on the Insiders Lounge page and that the
_aem_oidc_session_tokencookie is set (in your browser’s developer tools, open Application > Cookies).
-
On the Insiders Lounge page, select Sign out and confirm that you land on the
signed-outpage. Then open the protected page again and confirm that the sign-in is required again.
Step 8: Show the visitor’s name (optional)
The CDN can also return details about the signed-in visitor, so a page can greet them by name. To do that, request the profile scope from Google and add an endpoint that returns the identity data the CDN holds for the session.
Update the CDN configuration
By default, the authenticator asks Google only for the visitor’s identity and email address, using the openid and email scopes. To receive the visitor’s name and picture, you also request the profile scope, and then add endpoints that return the data.
-
In
config/cdn.yaml, addadditionalScopesto the authenticator:code language-yaml - name: frescopa-google-oidc type: oidc # ...existing settings... additionalScopes: [profile] -
Add two
respondrules next to the existingauthenticaterule, underauthentication.rules:code language-yaml rules: - name: frescopa-members-rule # ...existing rule... - name: frescopa-respond-with-user-email when: allOf: - { reqProperty: domain, equals: "dev-myfrescopa.enablementadobe.com" } - { reqProperty: path, equals: /members/email } action: type: respond status: 200 body: authProperty: oidcUserEmail - name: frescopa-respond-with-id-token when: allOf: - { reqProperty: domain, equals: "dev-myfrescopa.enablementadobe.com" } - { reqProperty: path, equals: /members/idtoken } action: type: respond status: 200 body: authProperty: oidcIdToken
additionalScopesopenid and email. The profile scope adds the visitor’s name and picture.type: respondbody field.authProperty: oidcUserEmailauthProperty: oidcIdTokenname, given_name, family_name, email, and picture.authenticate rule protects, such as /members/. On paths outside the protected area, the authenticator does not run and the properties return (null).For the complete configuration, see lines 44-65 of Frescopa’s cdn.yaml, which contain the two respond rules.
Commit the change and run the configuration pipeline again, as in Step 5. Then sign out and sign in again, because your existing session was issued without the profile scope.
Test in the browser
-
Sign in and open the protected page.
-
In the browser’s developer tools, open the Console and run:
code language-js fetch('/members/idtoken', { credentials: 'include' }) .then(r => r.json()) .then(t => console.log(t.given_name, t.family_name, t.picture)); -
Confirm that the console prints your first name, last name, and picture URL.
-
To check the email endpoint, run:
code language-js fetch('/members/email', { credentials: 'include' }) .then(r => r.text()) .then(console.log);It returns plain text, so use
r.text(), notr.json().
Show the name in the hero
To see the name on the page, run the following snippet in the browser console while you are on the protected Insiders Lounge page. It adds a greeting at the top of the hero text. It uses textContent, so values from the token are never interpreted as HTML.
(async () => {
const resp = await fetch('/members/idtoken', { credentials: 'include' });
if (!resp.ok) return;
const { given_name: givenName } = await resp.json();
const greeting = document.createElement('p');
greeting.textContent = `Welcome back, ${givenName}!`;
document.querySelector('main .hero > div:last-child > div').prepend(greeting);
})();
Confirm that Welcome back, <your first name>! appears in the hero. The change is temporary and disappears when you reload the page.
greeting, that fetches /members/idtoken in its decorate function and renders the name. Authors can then place it on any protected page./members/idtoken and /members/email endpoints return personal data about the signed-in visitor, so keep them under the protected path. Request only the scopes you need.Troubleshooting
redirect_uri_mismatchhttps://<domain>/callback.domain or path condition does not match (for example, a branch prefix such as /dev/branches/oidc is missing from the regular expression), or you opened the .aem.live hostname (see Step 6)./members/, asks for sign-inpath regular expression is too broad.callback path does not match the registered redirect URI, or issuer or jwksUri is wrong.signed-out page or the wrong pageloginTarget and logoutTarget in the authenticator configuration./members/email or /members/idtoken returns (null)authenticate rule, or the session was created before you added additionalScopes. Keep the path under /members/, then sign out and sign in again.given_name and family_name are missingadditionalScopes: [profile] is not deployed yet, or you did not sign in again after deploying it.${{...}}Summary
You restricted access to a /members/ section of the Frescopa Edge Delivery Services site with Google sign-in, enforced at the Adobe-managed CDN. You limited who can sign in at Google, kept the client secret out of Git, and learned how and why to restrict access to the .aem.live origin. Optionally, you also returned the visitor’s name and email from the CDN to greet them in a page.
Additional resources
- Frescopa’s
cdn.yamlconfiguration for reference, including theauthenticationblock (lines 18-43) and therespondrules (lines 44-65). - Adobe-managed CDN configuration: CDN OIDC authentication
- Edge Delivery configuration pipeline
- Use configs and secrets with Edge Functions
- Set up site authentication
- Configuring CDN credentials and authentication
- Google OpenID Connect documentation