auth0-angular by auth0/agent-skills
npx skills add https://github.com/auth0/agent-skills --skill auth0-angular使用 @auth0/auth0-angular 为 Angular 应用程序添加身份验证。
auth0-quickstart 技能auth0-react-native,对于 Ionic 使用原生 SDKnpm install @auth0/auth0-angular
要使用 Auth0 CLI 进行自动设置,请参阅设置指南以获取完整脚本。
要进行手动设置:
更新 :
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
src/environments/environment.tsexport const environment = {
production: false,
auth0: {
domain: 'your-tenant.auth0.com',
clientId: 'your-client-id',
authorizationParams: {
redirect_uri: window.location.origin
}
}
};
对于独立组件(Angular 14+):
更新 src/app/app.config.ts:
import { ApplicationConfig } from '@angular/core';
import { provideAuth0 } from '@auth0/auth0-angular';
import { environment } from '../environments/environment';
export const appConfig: ApplicationConfig = {
providers: [
provideAuth0({
domain: environment.auth0.domain,
clientId: environment.auth0.clientId,
authorizationParams: environment.auth0.authorizationParams
})
]
};
对于基于 NgModule 的应用程序:
更新 src/app/app.module.ts:
import { AuthModule } from '@auth0/auth0-angular';
import { environment } from '../environments/environment';
@NgModule({
imports: [
AuthModule.forRoot({
domain: environment.auth0.domain,
clientId: environment.auth0.clientId,
authorizationParams: environment.auth0.authorizationParams
})
]
})
export class AppModule {}
更新 src/app/app.component.ts:
import { Component } from '@angular/core';
import { AuthService } from '@auth0/auth0-angular';
@Component({
selector: 'app-root',
template: `
<div *ngIf="auth.isLoading$ | async; else loaded">
<p>Loading...</p>
</div>
<ng-template #loaded>
<ng-container *ngIf="auth.isAuthenticated$ | async; else loggedOut">
<div *ngIf="auth.user$ | async as user">
<img [src]="user.picture" [alt]="user.name" />
<h2>Welcome, {{ user.name }}!</h2>
<button (click)="logout()">Logout</button>
</div>
</ng-container>
<ng-template #loggedOut">
<button (click)="login()">Login</button>
</ng-template>
</ng-template>
`
})
export class AppComponent {
constructor(public auth: AuthService) {}
login(): void {
this.auth.loginWithRedirect();
}
logout(): void {
this.auth.logout({ logoutParams: { returnTo: window.location.origin } });
}
}
启动您的开发服务器并测试登录流程:
ng serve
| 错误 | 修复方法 |
|---|---|
| 忘记在 Auth0 仪表板中添加重定向 URI | 在 Auth0 仪表板的"允许的回调 URL"中添加您的应用程序 URL(例如 http://localhost:4200、https://app.example.com) |
| 未正确配置 AuthModule | 必须在 NgModule 中调用 AuthModule.forRoot() 或在独立配置中调用 provideAuth0() |
| 在初始化前访问身份验证信息 | 使用 isLoading$ 可观察对象等待 SDK 初始化 |
| 手动存储令牌 | 切勿手动存储令牌 - SDK 会自动处理安全存储 |
| 缺少 HTTP 拦截器 | 使用 authHttpInterceptorFn 或 AuthHttpInterceptor 将令牌附加到 API 调用 |
| 路由守卫未保护路由 | 在路由配置中对受保护的路由应用 AuthGuard(或 authGuardFn) |
auth0-quickstart - 基础 Auth0 设置auth0-migration - 从其他身份验证提供商迁移auth0-mfa - 添加多因素身份验证核心服务:
AuthService - 主要的身份验证服务isAuthenticated$ - 检查用户是否已登录的可观察对象user$ - 用户配置文件信息的可观察对象loginWithRedirect() - 发起登录logout() - 注销用户getAccessTokenSilently() - 获取用于 API 调用的访问令牌常见用例:
每周安装数
88
仓库
GitHub 星标数
11
首次出现
2026 年 2 月 6 日
安全审计
安装于
opencode82
github-copilot82
codex82
gemini-cli82
amp79
kimi-cli79
Add authentication to Angular applications using @auth0/auth0-angular.
auth0-quickstart skill firstauth0-react-native for React Native or native SDKs for Ionicnpm install @auth0/auth0-angular
For automated setup with Auth0 CLI , see Setup Guide for complete scripts.
For manual setup:
Update src/environments/environment.ts:
export const environment = {
production: false,
auth0: {
domain: 'your-tenant.auth0.com',
clientId: 'your-client-id',
authorizationParams: {
redirect_uri: window.location.origin
}
}
};
For standalone components (Angular 14+):
Update src/app/app.config.ts:
import { ApplicationConfig } from '@angular/core';
import { provideAuth0 } from '@auth0/auth0-angular';
import { environment } from '../environments/environment';
export const appConfig: ApplicationConfig = {
providers: [
provideAuth0({
domain: environment.auth0.domain,
clientId: environment.auth0.clientId,
authorizationParams: environment.auth0.authorizationParams
})
]
};
For NgModule-based apps:
Update src/app/app.module.ts:
import { AuthModule } from '@auth0/auth0-angular';
import { environment } from '../environments/environment';
@NgModule({
imports: [
AuthModule.forRoot({
domain: environment.auth0.domain,
clientId: environment.auth0.clientId,
authorizationParams: environment.auth0.authorizationParams
})
]
})
export class AppModule {}
Update src/app/app.component.ts:
import { Component } from '@angular/core';
import { AuthService } from '@auth0/auth0-angular';
@Component({
selector: 'app-root',
template: `
<div *ngIf="auth.isLoading$ | async; else loaded">
<p>Loading...</p>
</div>
<ng-template #loaded>
<ng-container *ngIf="auth.isAuthenticated$ | async; else loggedOut">
<div *ngIf="auth.user$ | async as user">
<img [src]="user.picture" [alt]="user.name" />
<h2>Welcome, {{ user.name }}!</h2>
<button (click)="logout()">Logout</button>
</div>
</ng-container>
<ng-template #loggedOut">
<button (click)="login()">Login</button>
</ng-template>
</ng-template>
`
})
export class AppComponent {
constructor(public auth: AuthService) {}
login(): void {
this.auth.loginWithRedirect();
}
logout(): void {
this.auth.logout({ logoutParams: { returnTo: window.location.origin } });
}
}
Start your dev server and test the login flow:
ng serve
| Mistake | Fix |
|---|---|
| Forgot to add redirect URI in Auth0 Dashboard | Add your application URL (e.g., http://localhost:4200, https://app.example.com) to Allowed Callback URLs in Auth0 Dashboard |
| Not configuring AuthModule properly | Must call AuthModule.forRoot() in NgModule or provideAuth0() in standalone config |
| Accessing auth before initialization | Use isLoading$ observable to wait for SDK initialization |
| Storing tokens manually | Never manually store tokens - SDK handles secure storage automatically |
| Missing HTTP interceptor | Use authHttpInterceptorFn or to attach tokens to API calls |
auth0-quickstart - Basic Auth0 setupauth0-migration - Migrate from another auth providerauth0-mfa - Add Multi-Factor AuthenticationCore Services:
AuthService - Main authentication serviceisAuthenticated$ - Observable check if user is logged inuser$ - Observable user profile informationloginWithRedirect() - Initiate loginlogout() - Log out usergetAccessTokenSilently() - Get access token for API callsCommon Use Cases:
Weekly Installs
88
Repository
GitHub Stars
11
First Seen
Feb 6, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykWarn
Installed on
opencode82
github-copilot82
codex82
gemini-cli82
amp79
kimi-cli79
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
42,100 周安装
如何构建MCP服务器:完整指南与最佳实践 | Claude插件开发
487 周安装
销售方法论实施指南:MEDDIC/BANT/SPIN等7大框架应用与团队赋能工具
111 周安装
Bash脚本精通指南:跨平台脚本编写、ShellCheck验证与DevOps自动化最佳实践
103 周安装
AI游戏美术生成:可控一致的游戏资产AI管线架构指南
71 周安装
Web 3D 集成模式:Three.js、React Three Fiber、GSAP、Framer Motion 多库整合架构指南
204 周安装
Python视频剪辑工具 - 按时间戳剪切、分割、修剪视频,保持原始质量
104 周安装
AuthHttpInterceptor| Route guard not protecting routes | Apply AuthGuard (or authGuardFn) to protected routes in routing config |