首页 > 解决方案 > 在离子 4 中对 MSAdal 进行身份验证后,正确的重定向 URI 是什么?

问题描述

我的问题是:当我从 Ionic 4 应用程序进行身份验证时,我想将其重定向到应用程序根页面。authContext.acquireTokenAsync 的正确重定向 URI 是什么?我有一个错误。

来自微软的回答。

 The reply url specified in the request does not match the reply urls configured for the application: '1111111111111111111111111111'.

我使用这样的代码。

let authContext: AuthenticationContext = this.msAdal.createAuthenticationContext('https://login.windows.net/common');

authContext.acquireTokenAsync('https://graph.windows.net', 'ClinetID', 'http://localhost:8000','','')
    .then((authResponse: AuthenticationResult) => {
      console.log('Token is' , authResponse.accessToken);
      console.log('Token will expire on', authResponse.expiresOn);
    })
    .catch((e: any) => console.log('Authentication failed', e));

标签: ionic-frameworkazure-active-directory

解决方案


您需要使用建议的重定向 url 或使用自定义重定向 url 在 Active Directory 上将应用注册为本地应用。

在此处输入图像描述

urn:ietf:wg:oauth:2.0:oob用作重定向网址,所以代码应该是

authContext.acquireTokenAsync('https://graph.windows.net','<Your Native App client ID>' , 'urn:ietf:wg:oauth:2.0:oob', '', null)

注意:您必须保持 azure 门户中的重定向 url 和代码中的重定向 url 相同。


推荐阅读