Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dns 如何知道我的web应用程序的应用程序\u客户端\u ID和您的\u AUTH0\u域_Dns_Angular6_Auth0_Clientid - Fatal编程技术网

Dns 如何知道我的web应用程序的应用程序\u客户端\u ID和您的\u AUTH0\u域

Dns 如何知道我的web应用程序的应用程序\u客户端\u ID和您的\u AUTH0\u域,dns,angular6,auth0,clientid,Dns,Angular6,Auth0,Clientid,我已经按照本指南创建了一个web应用程序 在指南中,他们创建auth0.ts文件 在那里,他们提到设置我的应用程序\u客户端\u ID和您的\u AUTH0\u域 我不知道这些证件从哪里来 这是我的auth.ts文件的代码 import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import * as auth0 from 'auth0-js'; (window as any).

我已经按照本指南创建了一个web应用程序

在指南中,他们创建auth0.ts文件

在那里,他们提到设置我的应用程序\u客户端\u ID和您的\u AUTH0\u域

我不知道这些证件从哪里来

这是我的
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;
  }
}
从'@angular/core'导入{Injectable};
从'@angular/Router'导入{Router};
从“auth0 js”导入*作为auth0;
(如有窗口)。全局=窗口;
@可注射()
导出类身份验证服务{
auth0=new auth0.WebAuth({
客户端ID:“”,
域:“”,
responseType:'令牌',
重定向URI:'http://localhost:4200/',
作用域:“openid”
});
accessToken:字符串;
expiresAt:编号;
构造函数(公共路由器:路由器){}
公共登录():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']);
}否则如果(错误){
this.router.navigate(['/']);
控制台日志(err);
}
});
}
公共注销():无效{
this.accessToken=null;
this.expiresAt=null;
this.router.navigate(['/']);
}
public isAuthenticated():布尔值{
返回新日期().getTime()
听起来好像您注册了Auth0并创建了一个应用程序

如果你转到你的应用程序,你会看到你的应用程序列表

单击应用程序的名称,您将进入应用程序设置页面。右边的小图标可以让你复制你需要的信息

如果你还没有注册,你可以免费注册

登录并需要创建新应用程序后,单击“+新应用程序”。从这里,您可以按照内置指南在Auth0中创建单页应用程序

创建应用程序后,可以将上述配置复制到
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;
  }
}
如果要从我的屏幕截图复制设置,则
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: 'c45ij324tg345bjnfojo2u6b4352',
    domain: 'your-auth0-domain.auth0.com',
    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;
  }
}
从'@angular/core'导入{Injectable};
从'@angular/Router'导入{Router};
从“auth0 js”导入*作为auth0;
(如有窗口)。全局=窗口;
@可注射()
导出类身份验证服务{
auth0=new auth0.WebAuth({
客户ID:'c45ij324tg345bjnfojo2u6b4352',
域:“your-auth0-domain.auth0.com”,
responseType:'令牌',
重定向URI:'http://localhost:4200/',
作用域:“openid”
});
accessToken:字符串;
expiresAt:编号;
构造函数(公共路由器:路由器){}
公共登录():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']);
}否则如果(错误){
this.router.navigate(['/']);
控制台日志(err);
}
});
}
公共注销():无效{
this.accessToken=null;
this.expiresAt=null;
this.router.navigate(['/']);
}
public isAuthenticated():布尔值{
返回新日期().getTime()

披露:我为Auth0工作。

完美的解释。