Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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
Angular 获得;“回调URL不匹配”;使用Auth0_Angular_Auth0 - Fatal编程技术网

Angular 获得;“回调URL不匹配”;使用Auth0

Angular 获得;“回调URL不匹配”;使用Auth0,angular,auth0,Angular,Auth0,我有一个配置了以下回调URL的Auth0客户端: 我可以很好地登录 问题是当我在应用程序中导航到某个URL时:http://localhost:4200/places。下面是发生的情况: 我导航到http://localhost:4200/places Angular将我(正确)重定向到http://localhost:4200 我尝试登录 我从Auth0收到一个错误,说“url”不在允许的回调url列表中 Auth0是正确的,http://localhost:4200/places不在我允许

我有一个配置了以下回调URL的Auth0客户端:

我可以很好地登录

问题是当我在应用程序中导航到某个URL时:
http://localhost:4200/places
。下面是发生的情况:

  • 我导航到
    http://localhost:4200/places
  • Angular将我(正确)重定向到
    http://localhost:4200
  • 我尝试登录
  • 我从Auth0收到一个错误,说“url”不在允许的回调url列表中
  • Auth0是正确的,
    http://localhost:4200/places
    不在我允许的回调URL列表中,我不希望这样。我不想列出我的用户可能被踢回登录屏幕的任何URL

    因此,出于某种原因,发生了一些事情,告诉Auth0引用的URL是
    http://localhost:4200/places
    而不是
    http://localhost:4200
    ,即使
    http://localhost:4200
    实际上是我尝试登录时地址栏中的URL

    我意识到我可以指定
    http://localhost:4200
    作为
    重定向URL
    并“修复”问题,但我必须使
    重定向URL
    在开发、登台和生产方面有所不同。这似乎不是人们通常回避这个问题的方式


    我怎样才能让Auth0不尝试将我重定向到
    /places

    我遇到了同样的问题,并通过上面史瑞克的建议解决了它(与我不同)。但是,我必须使用window.top.location.origin而不是window.top.location.hostname。对我来说,window.top.location.origin等同于Auth0中我的客户端设置中允许的回调URL值

    这是我的密码:

        let stateOptions =
        {
            "auth0_authorize": this.authNonce,
            "return_url": router.url
        };
    
        let options =
            {
                closable: false,
                languageDictionary:
                {
                    emailInputPlaceholder: "something@youremail.com",
                    title: "Log me in"
                },
                auth:
                {
                    redirectUrl: window.top.location.origin,
                    redirect: true,
                    responseType: 'token',
                    params:
                    {
                        state: btoa(JSON.stringify(stateOptions)),
                        scope: 'openid user_id name nickname email picture'
                    }
                }
            };
    
        this.lock = new Auth0Lock('[your-auth0-clientid]', '[your-auth0-domain]', options);
    

    这个问题也让我困惑了很长时间。最后,我在Auth0的配置页面中找到了它

    这样做很有趣。我不知道Auth0为什么使用这个来保存回调url。事实上,我们总是在代码中设置
    重定向URL
    。这与谷歌的授权完全不同。无论如何,问题解决了

    顺便说一句,我在一开始搜索这个错误,但我在Auth0配置页面中找到了这个解决方案。顶部有一个视频教程


    我希望这能有所帮助。

    这是因为您正在初始化锁,您可以从
    window.top.location.hostname
    ;)获取主机