Redirect 在Angular 2应用程序中获取回调URL不匹配

Redirect 在Angular 2应用程序中获取回调URL不匹配,redirect,angular,login,auth0,Redirect,Angular,Login,Auth0,我使用Auth0通过谷歌、Facebook和其他网站授权用户。如果您在URL位于Auth0中白色列表的回调URL列表上时单击“登录”,则此操作非常有效 但是我的web应用程序可以有任意数量的不同URL,因此使用带有一些允许URL的简单白名单是行不通的 登录总是尝试重定向回我登录时使用的同一URL,而此URL大多数情况下不在允许的URL列表中 我尝试了上述设置的各种变化,但我只得到如下错误: url“”不在允许的回调url列表中 url“”不在允许的回调url列表中 url“”不在允许的回调url

我使用Auth0通过谷歌、Facebook和其他网站授权用户。如果您在URL位于Auth0中白色列表的回调URL列表上时单击“登录”,则此操作非常有效

但是我的web应用程序可以有任意数量的不同URL,因此使用带有一些允许URL的简单白名单是行不通的

登录总是尝试重定向回我登录时使用的同一URL,而此URL大多数情况下不在允许的URL列表中

我尝试了上述设置的各种变化,但我只得到如下错误:

url“”不在允许的回调url列表中
url“”不在允许的回调url列表中
url“”不在允许的回调url列表中
url“”不在允许的回调url列表中

锁配置相关代码:

options = {
    auth: {
        callbackURL: 'https://x.com',
        // redirectUrl: 'https://x.com',
        responseType: 'token',
        // sso: true,
        // redirect: true,
        params: {
            scope: 'openid user_id name nickname email picture'
        }
    }
};

// Configure Auth0
lock = new Auth0Lock('x', 'x.auth0.com', this.options);

constructor(private _router: Router) {
    this.userProfile = JSON.parse(localStorage.getItem('profile'));

    // Add callback for the Lock `authenticated` event
    this.lock.on('authenticated', (authResult) => {
        localStorage.setItem('id_token', authResult.idToken);

        // Fetch profile information
        this.lock.getProfile(authResult.idToken, (error, profile) => {
            if (error) {
                throw new Error(error);
            }
        });
    });
};
登录方法:

public login() {
    // Call the show method to display the widget.
    this.lock.show({
        callbackUrl: 'https://x.com',
        state: this._router.url
    });
};

我假设您使用的是Lock()的最新版本,如果是这种情况,那么您所包含的代码存在一些问题:

  • 用户完成身份验证步骤后,将通过
    auth:{redirectUrl:'…'}
    指定,并且您对该行进行了注释,而代码使用的是错误的
    callbackURL
  • ,show方法不再接受任何参数
  • 独立于锁版本,应该使用该版本来缓解CSRF攻击,因此仅使用它来传递上下文信息可能是不安全的

如果您对
重定向URL
进行了评论,您可能也尝试了一下;在使用该参数时,您是否有相同的行为

根据文档,您试图实现的所需配置应通过以下方式完成:

options = {
    auth: {
        redirectUrl: 'https://example.com/login/callback',
        responseType: 'token',
        params: {
            state: '[your_state_value]',
            scope: 'openid user_id name nickname email picture'
        }
    }
};

public login() {
    // Call the show method to display the widget.
    this.lock.show();
};