【发布时间】:2019-05-05 23:39:16
【问题描述】:
我按照本指南 https://auth0.com/blog/creating-beautiful-apps-with-angular-material/ 创建了一个 Web 应用程序。
在指南中,他们创建了 auth0.ts 文件。
在那里,他们提到设置我的 APPLICATION_CLIENT_ID 和 YOUR_AUTH0_DOMAIN。
我不明白从哪里获得这些 ID。
这是我的auth.ts 文件的代码。
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import * as auth0 from 'auth0-js';
(window as any).global = window;
@Injectable()
export class AuthService {
auth0 = new auth0.WebAuth({
clientID: '<APPLICATION_CLIENT_ID>',
domain: '<YOUR_AUTH0_DOMAIN>',
responseType: 'token',
redirectUri: 'http://localhost:4200/',
scope: 'openid'
});
accessToken: String;
expiresAt: Number;
constructor(public router: Router) { }
public login(): void {
this.auth0.authorize();
}
public handleAuthentication(): void {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult.accessToken) {
window.location.hash = '';
this.accessToken = authResult.accessToken;
this.expiresAt = (authResult.expiresIn * 1000) + new Date().getTime();
this.router.navigate(['/dashboard']);
} else if (err) {
this.router.navigate(['/']);
console.log(err);
}
});
}
public logout(): void {
this.accessToken = null;
this.expiresAt = null;
this.router.navigate(['/']);
}
public isAuthenticated(): boolean {
return new Date().getTime() < this.expiresAt;
}
}
【问题讨论】:
标签: dns angular6 auth0 clientid