百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

auth0-angular

> 前端框架
开源

用于 Angular 单页面应用程序的 Auth0 SDK

200 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于 Angular 单页面应用程序的 Auth0 SDK

A library for integrating Auth0 into an Angular application.

Documentation - Getting Started - API Reference - Feedback

Documentation

  • Quickstart - our interactive guide for quickly adding login, logout and user information to an Angular app using Auth0.
  • Sample App - a full-fledged Angular application integrated with Auth0.
  • FAQs - frequently asked questions about the auth0-angular SDK.
  • Examples - code samples for common Angular authentication scenario's.
  • Docs site - explore our docs site and learn more about Auth0.

Getting started

Requirements

This project only supports the actively supported versions of Angular as stated in the Angular documentation. Whilst other versions might be compatible they are not actively supported.

Installation

Using npm:

bash
npm install @auth0/auth0-angular

We also have ng-add support, so the library can also be installed using the Angular CLI:

bash
ng add @auth0/auth0-angular

Configure Auth0

Create a Single Page Application in the Auth0 Dashboard.

If you're using an existing application, verify that you have configured the following settings in your Single Page Application:

  • Click on the "Settings" tab of your application's page.
  • Scroll down and click on the "Show Advanced Settings" link.
  • Under "Advanced Settings", click on the "OAuth" tab.
  • Ensure that "JsonWebToken Signature Algorithm" is set to RS256 and that "OIDC Conformant" is enabled.

Next, configure the following URLs for your application under the "Application URIs" section of the "Settings" page:

  • Allowed Callback URLs: http://localhost:4200
  • Allowed Logout URLs: http://localhost:4200
  • Allowed Web Origins: http://localhost:4200

These URLs should reflect the origins that your application is running on. Allowed Callback URLs may also include a path, depending on where you're handling the callback.

Take note of the Client ID and Domain values under the "Basic Information" section. You'll need these values in the next step.

Configure the SDK

Static configuration

The recommended approach is to use the functional provideAuth0() in your application configuration:

typescript
import { ApplicationConfig } from '@angular/core';
import { provideAuth0 } from '@auth0/auth0-angular';

export const appConfig: ApplicationConfig = {
  providers: [
    provideAuth0({
      domain: 'YOUR_AUTH0_DOMAIN',
      clientId: 'YOUR_AUTH0_CLIENT_ID',
      authorizationParams: {
        redirect_uri: window.location.origin,
      },
    }),
  ],
};

Using NgModules

If you're using NgModules, you can configure the SDK using AuthModule.forRoot():

typescript
import { NgModule } from '@angular/core';
import { AuthModule } from '@auth0/auth0-angular';

@NgModule({
  imports: [
    AuthModule.forRoot({
      domain: 'YOUR_AUTH0_DOMAIN',
      clientId: 'YOUR_AUTH0_CLIENT_ID',
      authorizationParams: {
        redirect_uri: window.location.origin,
      },
    }),
  ],
})
export class AppModule {}

Dynamic configuration

Instead of providing static configuration, you can use provideAppInitializer to load your config from an external source before the SDK is instantiated, and configure it using AuthClientConfig.set.

…

Important: The configuration will only be used initially when the SDK is instantiated. Any changes made to the configuration at a later moment in time will have no effect on the default options used when calling the SDK's methods. This is why the dynamic configuration should be set using an app initializer, which ensures the configuration is available prior to instantiating the SDK.

:information_source: Any request made through an instance of HttpClient that got instantiated by Angular will use all configured interceptors, including our AuthHttpInterceptor. Because the AuthHttpInterceptor requires the existence of configuration settings, the request for retrieving those dynamic configuration settings should ensure it's not using any interceptors. In Angular, this can be done by manually instantiating HttpClient using an injected HttpBackend instance.

Using NgModules

Instead of using AuthModule.forRoot to specify auth configuration, you can provide a factory function using APP_INITIALIZER to load your config from an external source before the auth module is loaded, and provide your configuration using AuthClientConfig.set.

…

Add login to your application

To log the user into the application, inject the AuthService and call its loginWithRedirect method.

typescript
import { Component } from '@angular/core';
import { AuthService } from '@auth0/auth0-angular';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  constructor(public auth: AuthService) {}

  loginWithRedirect() {
    this.auth.loginWithRedirect();
  }

By default the application will ask Auth0 to redirect back to the root URL of your application after authentication. This can be configured by setting the redirectUri option.

For more code samples on how to integrate the auth0-angular SDK in your Angular application, including how to use our standalone and function APIs, have a look at the examples.

API reference

Explore public API's available in auth0-angular.

  • AuthService - service used to interact with the SDK.
  • AuthConfig - used to configure the SDK.

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

  • Auth0's general contribution guidelines
  • Auth0's code of conduct guidelines

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

Issues· 3 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptangularauth0auth0-spa-jsauthentication

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架