Angular Auth0回调URL的实时和开发

Angular Auth0回调URL的实时和开发,angular,authentication,callback,auth0,Angular,Authentication,Callback,Auth0,我目前有一个Angular 2应用程序,它使用Auth0进行身份验证。一切正常,但登录服务中的回调url仅适用于实时网站。因此,当我在localhost上运行开发代码并登录时,它总是将我重定向到我的网站的实时版本,我不想在部署和本地测试之间来回更改一行代码。下面是auth.service.ts中的登录方法 public login(): void { this.auth0.authorize({ responseType: 'token id_token', audience: 'ht

我目前有一个Angular 2应用程序,它使用Auth0进行身份验证。一切正常,但登录服务中的回调url仅适用于实时网站。因此,当我在localhost上运行开发代码并登录时,它总是将我重定向到我的网站的实时版本,我不想在部署和本地测试之间来回更改一行代码。下面是auth.service.ts中的登录方法

public login(): void {

this.auth0.authorize({
  responseType: 'token id_token',
  audience: 'https://xxxxxx/userinfo',
  redirectUri: 'http://www.mylivewebsite.com/callback',      
  scope: 'openid'
});
我在本地测试应用程序时使用此选项

public login(): void {

this.auth0.authorize({
  responseType: 'token id_token',
  audience: 'https://xxxxxx/userinfo',
  redirectUri: 'http://localhost:4200/callback',      
  scope: 'openid'
});

有没有办法检测我来自哪个URL并进行相应调整?我觉得有一个简单的答案,但我似乎找不到一种方法使它工作。

我处理这个问题的方法是使用环境变量。许多人会使用NODE_ENV来确定应用程序是在开发还是在生产中

您可以这样做:

public login():void{
此文件为.auth0.authorize({
responseType:“令牌id\u令牌”,
观众:'https://xxxxxx/userinfo',
redirectUri:(process.env.NODE_env==='production')?[deploy url]:[dev url],
作用域:“openid”
});

我处理这个问题的方法是使用环境变量。许多人会使用NODE_ENV来确定应用程序是在开发还是在生产中

您可以这样做:

public login():void{
此文件为.auth0.authorize({
responseType:“令牌id\u令牌”,
观众:'https://xxxxxx/userinfo',
redirectUri:(process.env.NODE_env==='production')?[deploy url]:[dev url],
作用域:“openid”
});