azure - 使用 Azure AD 进行身份验证,手动 GET 请求成功,但使用 .net Framework 应用程序失败

标签 azure authentication active-directory adal

我遵循本指南 (enter link description here) 来访问 Skype for Business 资源。当我尝试使用 InsomniaPostman 时,一切都很顺利,但当我使用 .net 框架应用程序执行此操作时,一切都会失败。首先让我们看看手动调用:每当我发出下图所示的 GET 请求时,我都会被重定向到 Microsoft 的登录页面,我使用我的凭据登录,作为返回(在 url 中)我看到了我需要的身份验证 token 下一步。

enter image description here

现在,我尝试通过我的 .net Framework 应用程序实现相同的行为,但它表示我需要一个客户端 key ,但我在手动调用中不使用该 key 。代码如下:

enter image description here

因此应用程序运行,弹出插入我的凭据的窗口,我输入我的用户名和密码,然后出现以下错误:

enter image description here

可能与 RedirectUri 有关吗?如果手动调用成功,在插入凭据后,我会被重定向到redirect_uri中指定的页面(在我的情况下不起作用),但至少我拿回了 token ,请参见图片:

enter image description here

最佳答案

如果您使用的是webapp/api应用类型,则需要传递clientSecret来获取token。这是代码示例。

var authContext = new AuthenticationContext(context.Options.Authority, new NaiveSessionCache(userObjectId, context.HttpContext.Session));
                var credential = new ClientCredential(context.Options.ClientId, context.Options.ClientSecret);
                var token2 = await authContext.AcquireTokenAsync(context.Options.Resource,credential);

enter image description here

如果您不想通过clientSecret来获取token,则需要使用NativeClient应用类型。

您可以在 Azure 门户上找到您的应用程序类型。 enter image description here

关于azure - 使用 Azure AD 进行身份验证,手动 GET 请求成功,但使用 .net Framework 应用程序失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55144232/

相关文章:

java - 如何以编程方式加密/解密 JSP 中的纯文本凭据?

asp.net - HttpContext.Current.User.Identity.Name 在同一网站的所有应用程序之间共享 : isn't this insecure?

Azure AD 读取扩展属性

c# - 单个 PrincipalContext 能否在应用程序的生命周期内重复使用?

azure - 定期自动生成 Azure Batch AI 作业

Azure 负载平衡集保留客户端 IP

asp.net - 我可以在一个 Web 应用程序中跨多个服务使用身份验证吗?

windows - Active Directory 中是否存在任何主键(或)唯一键?

azure - 针对 Windows Azure Active Directory 的 ASP.NET 身份验证出现 ACS50001 错误

c# - 同一线程可以在 Azure Functions 中同时运行多个函数吗?