Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/config/navigation/quickstarts.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"docs/quickstart/webapp/laravel/interactive",
"docs/quickstart/webapp/php/interactive",
"docs/quickstart/webapp/nginx-plus/interactive",
"docs/quickstart/webapp/apache/interactive",
"docs/quickstart/webapp/apache/index",
"docs/quickstart/webapp/rails/interactive",
"docs/quickstart/webapp/hono/index"
]
Expand Down
4 changes: 4 additions & 0 deletions main/config/redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -22298,5 +22298,9 @@
{
"source": "/docs/ja-jp/secure/mdl-verification/*",
"destination": "/docs/ja-jp/secure"
},
{
"source": "/docs/quickstart/webapp/apache/interactive",
"destination": "/docs/quickstart/webapp/apache"
}
]
105 changes: 0 additions & 105 deletions main/docs/quickstart/webapp/apache/_index.mdx

This file was deleted.

171 changes: 86 additions & 85 deletions main/docs/quickstart/webapp/apache/index.mdx
Original file line number Diff line number Diff line change
@@ -1,128 +1,129 @@
---
title: "Apache"
mode: wide
description: This tutorial demonstrates how to configure Apache to add authentication and authorization to your web app.
sidebarTitle: Apache
title: Add Login to Your Apache Application
---
import {AuthCodeBlock} from "/snippets/AuthCodeBlock.jsx";


Community maintained

This tutorial demonstrates how to use the Auth0 Apache SDK to add authentication and authorization to your web app.We recommend that you log in to follow this quickstart with examples configured for your account.

<Note>
### System Requirements

This tutorial and seed project have been tested with the following:

* Apache 2.4
</Note>

**Please follow the steps below to configure your application using Apache to work with Auth0 and Open ID Connect.**

## Install and Enable mod_auth_openidc Module

First, you need to install the `mod_auth_openidc` module for Apache.

You can get the binaries from [Github](https://github.com/zmartzone/mod_auth_openidc/releases) and install them for your OS. If your OS isn't compatible with any of the binaries, you can still [build it from source](https://github.com/zmartzone/mod_auth_openidc/blob/master/INSTALL)

Once you've installed it, you just need to enable it for Apache (If you are using Windows, you can use [this](https://github.com/enderandpeter/win-a2enmod#installation) to get `a2enmod` working on your system)

```bash lines
a2enmod auth_openidc
```




import {AuthCodeBlock} from "/snippets/AuthCodeBlock.jsx";


## Configure the Module with Your Auth0 Account Information

Now you should get a new configuration file under the `/etc/apache2/mods-available` folder, where Apache modules are normally installed (On Windows you need to use `/apache/conf/httpd.conf` file).

In there, you must add the following configuration for the `mod_auth_openidc` module

export const codeExample = `# mods-available/auth_openidc.conf

OIDCProviderMetadataURL https://{yourDomain}/.well-known/openid-configuration
export const configSnippet = `OIDCProviderMetadataURL https://{yourDomain}/.well-known/openid-configuration
OIDCClientID {yourClientId}
OIDCClientSecret '{yourClientSecret}'
OIDCClientSecret {yourClientSecret}

OIDCScope "openid name email"
OIDCRedirectURI https://your_apache_server/your_path/redirect_uri/
OIDCCryptoPassphrase <passwordToEncryptTheSessionInformationOnTheCookie>

<Location /your_path>
AuthType openid-connect
Require valid-user
LogLevel debug
AuthType openid-connect
Require valid-user
LogLevel debug
</Location>

<Location /admin>
AuthType openid-connect
#Require valid-user
Require claim folder:admin
</Location>`;

<AuthCodeBlock children={codeExample} language="conf" />
<Accordion title="Use AI to integrate Auth0" icon="microchip-ai" iconType="solid" defaultOpen>

If you use an AI coding assistant like Claude Code, Cursor, or GitHub Copilot, you can add Auth0 authentication automatically in minutes using [agent skills](https://agentskills.io/home).

**Install:**

```bash
npx skills add auth0/agent-skills --skill auth0-quickstart --skill auth0-apache
```

**Then ask your AI assistant:**

```text
Add Auth0 authentication to my Apache server
```

## Configuring Auth0 Settings
Your AI assistant will automatically create your Auth0 application, fetch credentials, and configure mod_auth_openidc. [Full agent skills documentation →](/docs/quickstart/agent-skills)

In your application settings add a new allowed callback which is equal to `OIDCRedirectURI`.
</Accordion>

Now, go to OAuth section in advanced settings and change `JsonWebToken Token Signature Algorithm` to RS256.
<Note>
**System Requirements**

## Authorization
This tutorial and sample project have been tested with the following:

You can configure Apache to protect a certain location based on an attribute of the user. Here is an example:
- Apache 2.4
</Note>

```conf lines
# mods-available/auth_openidc.conf
## Get Started

<Location /example>
AuthType openid-connect
#Require valid-user
Require claim folder:example
</Location>
This tutorial demonstrates how to configure Apache to add authentication and authorization to your web app. We recommend that you log in to follow this quickstart with examples configured for your account.

<Location /example2>
AuthType openid-connect
#Require valid-user
Require claim folder:example2
</Location>
```
<Steps>
<Step title="Install and Enable mod_auth_openidc Module" stepNumber={1}>
First, install the `mod_auth_openidc` module for Apache.

You can get the binaries from [GitHub](https://github.com/OpenIDC/mod_auth_openidc/releases) and install them for your OS. If your OS isn't compatible with any of the binaries, you can still [build it from source](https://github.com/OpenIDC/mod_auth_openidc/blob/master/INSTALL).

Once you've installed the module, enable it for Apache with the `a2enmod` command. To learn more, read [a2enmod on Ubuntu Manpage](https://manpages.ubuntu.com/manpages/focal/man8/a2enmod.8.html):

```shellscript
a2enmod auth_openidc
```

<Info>
For Windows, you can use [this Powershell script](https://github.com/enderandpeter/win-a2enmod#installation) to get `a2enmod` working on your system.
</Info>
</Step>

<Step title="Configure the Module with Your Auth0 Account Information" stepNumber={2}>
Update your new configuration file (`auth_openidc.conf`), located in the `/etc/apache2/mods-available` folder.

Then you can write a rule in Auth0 that would return the `folder` attribute:
<Info>
For Windows, you must use the `/apache/conf/httpd.conf` file.
</Info>

```javascript lines
function(user, context, callback) {
if (somecondition()) {
user.folder = 'example2';
}
<AuthCodeBlock children={configSnippet} language="apache" filename="auth_openidc.conf" />
</Step>

user.folder = 'example';
}
```
<Step title="Configure Auth0" stepNumber={3}>
In the [Auth0 Dashboard](https://manage.auth0.com/):

1. Go to **Applications** > **Applications**, and then select your application from the list.
2. Switch to the **Settings** view, and then locate the **Application URIs** section.
3. Add the value of `OIDCRedirectURI` to **Allowed Callback URLs**.
4. Locate **Advanced Settings** at the bottom of the page.
5. Switch to the **OAuth** view.
6. Set **JSON Web Token (JWT) Signature Algorithm** to `RS256`.
</Step>

<Step title="Authorization" stepNumber={4}>
You can configure Apache to protect a specific location based on the value of a claim in the user's ID token by adding a `Location` block to your `auth_openidc.conf` file.

For example, you could create an Action that reads the user's roles, and then adds a claim that grants access to a protected location:

```js lines
exports.onExecutePostLogin = async (event, api) => {
const roles = event.authorization.roles; // ['user', 'admin']
if (roles.includes('admin')) {
api.idToken.setCustomClaim('folder', 'admin');
}
};
```
</Step>
</Steps>

<Check>
**Checkpoint**

Excellent work! If you made it this far, you should now have login, logout, and user profile information running in your application.
</Check>

Or you could even use an array of folders and the apache module will check if the array contains any of these values
---

```javascript lines
function(user, context, callback) {
user.folders = [];
if (somecondition()) {
user.folders.push('example2');
}
## Next Steps

user.folders.push('example');
}
```
This concludes our quickstart tutorial, but there is so much more to explore. To learn more about what you can do with Auth0, check out:

[Edit on GitHub](https://github.com/auth0/docs/edit/master/articles/quickstart/webapp/apache/01-login.md)
- [Auth0 Dashboard](https://manage.auth0.com/) - Learn how to configure and manage your Auth0 tenant and applications
- [Auth0 Marketplace](https://marketplace.auth0.com/) - Discover integrations you can enable to extend Auth0's functionality
Loading
Loading