# Angular

## [Overview](/content/docs/sdk-examples/angular#overview/index.html)

[Angular](https://angular.dev/) is a TypeScript-based framework for building web applications. This example demonstrates how to integrate **Zitadel** using the **[OAuth 2.0 PKCE flow](https://oauth.net/2/pkce/)** to authenticate users securely and maintain sessions across your Angular application.

#### [Auth library](/content/docs/sdk-examples/angular#auth-library/index.html)

This example uses **[@edgeflare/ngx-oidc](https://www.npmjs.com/package/@edgeflare/ngx-oidc)** (built on **[oidc-client-ts](https://www.npmjs.com/package/oidc-client-ts)**) to implement the [OpenID Connect (OIDC)](/content/docs/apis/openidoauth/endpoints/index.html) protocol, manage [PKCE](https://oauth.net/2/pkce/) code challenge generation, perform secure token exchange, and provide session management helpers.

---

## [What this example demonstrates](/content/docs/sdk-examples/angular#what-this-example-demonstrates/index.html)

This Angular application showcases a complete authentication pattern using [Zitadel](/content/docs/index.html) with [PKCE](https://oauth.net/2/pkce/). Users begin on a public landing page where they can initiate sign-in with Zitadel's authorization server. After successful authentication, the app handles the OAuth callback and redirects users to a protected profile page displaying their [user information and claims](/content/docs/apis/openidoauth/claims/index.html).

The application integrates authentication logic into Angular routing: protected routes use router guards to automatically redirect unauthenticated users to the sign-in flow, and callback routes complete the PKCE exchange and restore session state. The example requests standard OIDC scopes (`openid`, `profile`, `email`), `offline_access` for refresh tokens, and Zitadel-specific scopes for metadata and role information.

The example includes secure sign-out functionality implementing **[federated logout](/content/docs/guides/integrate/login/oidc/logout/index.html)** through Zitadel's end-session endpoint, which terminates both the local application session and the Zitadel session, then redirects the user back to the application.

---

## [Getting started](/content/docs/sdk-examples/angular#getting-started/index.html)

### [Prerequisites](/content/docs/sdk-examples/angular#prerequisites/index.html)

Before running this example, you need to create and configure a PKCE application in the [Zitadel Console](/content/docs/guides/manage/console/console-overview/index.html). Follow the PKCE application setup guide to:

1. Create a new Web application in your [Zitadel project](/content/docs/guides/manage/console/projects-overview/index.html)
2. Configure it to use the PKCE authentication method
3. Set up your redirect URIs (e.g., `http://localhost:3000/auth/callback` for development)
4. Configure post-logout redirect URIs (e.g., `http://localhost:3000/auth/logout/callback`)
5. Copy your **Client ID** for use in the next steps
6. Optionally enable [refresh tokens](/content/docs/apis/openidoauth/grant-types#refresh-token/index.html) in Token Settings for long-lived sessions

> **Note:** Make sure to enable **Dev Mode** in the [Zitadel Console](/content/docs/guides/manage/console/console-overview/index.html) if you're using HTTP URLs during local development. For production deployments, always use HTTPS URLs and disable Dev Mode.

### [Run the example](/content/docs/sdk-examples/angular#run-the-example/index.html)

Once you have your [Zitadel application configured](/content/docs/guides/integrate/login/oidc/login-users/index.html):

1. Clone the [repository](https://github.com/zitadel/example-auth-angular).
2. Create a `.env` file (copy from `.env.example`) and configure it with the values from your [Zitadel application](/content/docs/guides/manage/console/applications-overview/index.html). Use these environment variable names exactly as shown:

```
NODE_ENV=development
PORT=3000
NG_APP_ZITADEL_DOMAIN=https://your-zitadel-domain
NG_APP_ZITADEL_CLIENT_ID=your-zitadel-application-client-id
NG_APP_ZITADEL_CLIENT_SECRET=
NG_APP_ZITADEL_CALLBACK_URL=http://localhost:3000/auth/callback
NG_APP_ZITADEL_POST_LOGIN_URL=/profile
NG_APP_ZITADEL_POST_LOGOUT_URL=http://localhost:3000/auth/logout/callback
```

Replace these values with:
   - Your actual [Zitadel instance URL](/content/docs/guides/manage/console/default-settings/index.html) (the **NG_APP_ZITADEL_DOMAIN**)
   - The **Client ID** you copied when creating the application
   - The **redirect URIs** you configured in the PKCE setup (must match exactly)
   - The **post-logout redirect URIs** you configured (must match exactly)
3. Install dependencies using [npm](https://www.npmjs.com/) and start the development server to verify the authentication flow end-to-end.

---

## [Learn more and resources](/content/docs/sdk-examples/angular#learn-more-and-resources/index.html)

- [PKCE concept](https://oauth.net/2/pkce/)
- [Federated logout](/content/docs/guides/integrate/login/oidc/logout/index.html)
- [OIDC integration guide](/content/docs/guides/integrate/login/oidc/login-users/index.html)
- [Angular documentation](https://angular.dev/)
- [@edgeflare/ngx-oidc package](https://www.npmjs.com/package/@edgeflare/ngx-oidc)
- [oidc-client-ts package](https://www.npmjs.com/package/oidc-client-ts)
- [Example repository](https://github.com/zitadel/example-auth-angular)
