> For the complete documentation index, see [llms.txt](https://docs.authgear.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.authgear.com/~/changes/S9PzpQKqtjCE4EDWHGO4/get-started/authentication-approach/cookie-based.md).

# Cookie-based (Website or Single-page app)

Authenticate incoming request by cookie in the HTTP header.

By using Authgear, you can add a login to your website easily. Authgear supports various authentication methods, that you can easily turn on and configure in the portal.

## Prerequisites

To authenticate with cookies, you will need to set up a custom domain for Authgear, so that your website and Authgear are under the same root domains. e.g. Your website is `yourdomain.com`, and Authgear with a custom domain `auth.yourdomain.com`.

In this setting, if you have multiple applications under `yourdomain.com`, all applications would share the same session cookies automatically.

## **Overview**

### **How it works**

Your app server will receive a request with the cookie

![](https://mermaid.ink/img/eyJjb2RlIjoic2VxdWVuY2VEaWFncmFtXG4gICAgcGFydGljaXBhbnQgQ2xpZW50QXBwIGFzIEJyb3dzZXJcbiAgICBwYXJ0aWNpcGFudCBBdXRoZ2VhciBhcyBBdXRoZ2VhclxuICAgIHBhcnRpY2lwYW50IEFwcEJhY2tlbmQgYXMgWW91ciBBcHAgU2VydmVyXG4gICAgQ2xpZW50QXBwLT4-QXV0aGdlYXI6IDEuIFVzZXIgYXV0aGVudGljYXRlcyB3aXRoIEF1dGhnZWFyXG4gICAgQXV0aGdlYXItPj5DbGllbnRBcHA6IDIuIEF1dGhnZWFyIHNldHMgY29va2llXG4gICAgQ2xpZW50QXBwLT4-QXBwQmFja2VuZDogMy4gUmVxdWVzdCB3aXRoIGNvb2tpZVxuICAgIEFwcEJhY2tlbmQtPj5BcHBCYWNrZW5kOiA0LiBWZXJpZnkgUmVxdWVzdFxuICAgIEFwcEJhY2tlbmQtPj5DbGllbnRBcHA6IDUuIFNlcnZlciByZXNwb25kcyB3aXRoIHRoZSByZXF1ZXN0ZWQgaW5mb3JtYXRpb25cbiAgICAgICAgICAgICIsIm1lcm1haWQiOnt9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ)

### **Verify request in your app server**

To verify the requests in your app server, you must **Forward authentication to Authgear Resolver Endpoint.**

![Forwarding authentication to Authgear Resolver Endpoint](https://mermaid.ink/img/eyJjb2RlIjoiZmxvd2NoYXJ0IFREXG4gICAgYXV0aGdlYXJbQXV0aGdlYXJdXG4gICAgYXBwW1lvdXIgQXBwIFNlcnZlcl1cbiAgICBcbiAgICBhcHAgLS0-IHwgRm9yd2FyZCBhdXRoZW50aWNhdGlvbiB0byA8YnIvPiBBdXRoZ2VhciByZXNvbHZlciBlbmRwb2ludCB8IGF1dGhnZWFyXG4iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ)

## Request example

```javascript
> GET /api_path HTTP/1.1
> Host: yourdomain.com
> cookie: session=<AUTHGEAR_SESSION_ID>
```

## Get Started <a href="#get-started" id="get-started"></a>

The following tutorials show you how to add user login to your website using Authgear.

### 1. Frontend Integration

{% content-ref url="/pages/-MbFM4jUPTE\_6LJF1OEe" %}
[JavaScript (Web)](/~/changes/S9PzpQKqtjCE4EDWHGO4/get-started/single-page-app/website.md)
{% endcontent-ref %}

### 2. Backend Integration

{% content-ref url="/pages/-MbFM4jVKFT7n6gMYXXp" %}
[Backend Integration](/~/changes/S9PzpQKqtjCE4EDWHGO4/get-started/backend-api/backend-integration.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.authgear.com/~/changes/S9PzpQKqtjCE4EDWHGO4/get-started/authentication-approach/cookie-based.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
