【问题标题】:Angularjs doesn't authenticate with Azure Active DirectoryAngularjs 不使用 Azure Active Directory 进行身份验证
【发布时间】:2015-02-26 05:53:58
【问题描述】:

我有一个使用 Azure Active Directory 进行身份验证的 angularjs Web 应用程序。 应用程序使用的 Web Api 进行身份验证,没有任何错误。

对于客户端身份验证,我使用 adal.js 和 adal-angular.js。 当我尝试访问我的应用程序中的任何页面时,身份验证失败并在控制台中打印以下消息

The returned id_token is not parseable.
Route change event for:/
Start login at:https://localhost:44308/#
Navigate url:https://login.windows.net/myapp.onmicrosoft.com/oauth2/authorize
Navigate to:https://login.windows.net/myapp.onmicrosoft.com/oauth2/authorize
TypeError: Cannot read property 'data' of undefined

我已经关注this 教程。

有谁知道发生了什么或者我该如何调试?

【问题讨论】:

    标签: angularjs authentication azure adal


    【解决方案1】:

    当令牌没有正确解码 utf-8 字符时,错误出现在 adal.js 库中。

    带有错误修复的库的更新版本即将推出。

    【讨论】:

    • 我也遇到了同样的问题。你能解决这个问题吗?
    • 是的,我的错误是,库无法正确解码用户名中的希腊字符。没有希腊字符的用户没有问题。这已针对希腊字符修复。也许用户 tou 正在尝试登录在任何属性中都有特殊字符? (例如名字,姓氏...)
    【解决方案2】:

    不看代码示例就很难回答。如果你正在使用 Promise,如果 Promise 被拒绝,你需要处理这种情况。你可能有这样的事情:

        myAuthService.authenticate(...).then(function(data){
           //this handles the successful call.
        });
    

    你需要看到的错误是这样的:

            myAuthService.authenticate(...).then(function(data){
               //this handles the successful call.
            }, function(e){
               //this handles the error case
               alert('errror.  inspect this.arguments');
    });
    

    您应该发布引发错误的代码。

    【讨论】:

    • 正如您在发布的链接中看到的,唯一的代码是初始化库的代码。有一个事件会因错误而触发,但似乎无济于事......
    • 如果您共享代码示例而不是共享指向您尝试遵循的任何教程的链接,您将获得更好的答案。请参阅“帮助他人重现问题”部分:*.com/help/how-to-ask
    • 问题似乎是库中的一个错误......我修复了这个并且工作正常!还是谢谢