【问题标题】:How do you setup Microsoft OpenIdConnect?如何设置 Microsoft OpenIdConnect?
【发布时间】:2017-09-29 06:06:02
【问题描述】:

我花了很多时间尝试进行此设置,但似乎从未取得成功。我还没有找到任何似乎将最新配置放在一起并工作的示例。

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
    AuthenticationScheme = "Cookies",
    AutomaticAuthenticate = true
});

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions()
{
    AuthenticationScheme = "Microsoft Signin",
    SignInScheme = "Cookies",
    Authority = "https://login.microsoftonline.com/common/v2.0",
    ResponseType = "id_token",
    ClientId =    "XXXXXXXXXXXXXXXXX",
    ClientSecret = "XXXXXXXXXXXXX",
    SaveTokens = true
});

我设置了一个 Microsoft 应用程序来创建应用程序 ID 和密码。然后我将 RedirectUrls 设置为 http://localhost:12343/signin-microsoft,这是我的应用程序的当前位置。当我尝试进行身份验证时,我收到此错误。

We're unable to complete your request
Microsoft account is experiencing technical problems. Please try again later.

在 URL 地址中嵌入了另一个错误。

The provided value for the input parameter 'redirect_uri' is not valid. The 
expected value is 'https://login.live.com/oauth20_desktop.srf' or a URL which 
matches the redirect URI registered for this client application.

我已经尝试了所有我能想到的变体,但似乎没有任何效果。我还使用在线托管的代码尝试了这些事情,以防负责身份验证的服务器找不到本地主机但仍然没有运气。

我现在已将 microsoft 应用程序 RedirectUrls 的值更改为

http://localhost:10223/signin-oidc

当我进行身份验证时,它现在将我发送回此位置,但我收到 500 错误。

【问题讨论】:

  • 你看了吗...docs.microsoft.com/en-us/aspnet/core/security/authentication/…他们似乎有一步一步的教程...
  • 这与 OpenIdConnect 有什么不同吗?似乎只是身份验证。
  • 当您有用户使用中间件登录时,您应该能够遍历并查看 MSFT 已通过的声明,前提是用户授予了权限。
  • @Muqeet Khan。我将如何进行声明的迭代?
  • 您必须为您的网站启用 ssl

标签: authentication configuration asp.net-core azure-active-directory openid-connect


【解决方案1】:

您可以使用 Fiddler 抓取请求,比较redirect_uri 的值和应用注册门户中的一个配置。

此外,您可以查看this code sample,它将 Azure AD(v2.0 端点)集成到 ASP.NET Core Web 应用程序中。该代码示例使用 ASP.Net Core OpenID Connect 中间件,并允许登录用户使用 Microsoft 帐户和来自多个 Azure Active Directory 租户的帐户。

在制作上述代码示例过程中有任何问题,请随时告诉我。

【讨论】:

  • 您链接的项目没有使用我试图设置的 aspnetcore。 Microsoft.AspNetCore.Authentication.OpenIdConnect
  • @jwize,你检查过项目吗,它是一个.net核心项目,使用Microsoft.AspNetCore.Authentication.OpenIdConnect v1.0.0
  • 您查看您发布的链接了吗?我再次查看了该项目并搜索了 AspNetCore,但没有找到任何结果,所以看起来很奇怪..
  • 请查看code part,它是IIS上的asp.net核心应用宿主,你的方案是什么?
【解决方案2】:

问题是我正在关注使用

的示例
app.UseOpenIdConnectAuthentication

有些扩展可以设置选项来解决大部分缺失的部分。

var googleOptions = new GoogleOptions() { ... }
var facebookOptions = new FacebookOptions() { ... }
var twitterOptions = new TwitterOptions() { ... }
var options = new MicrosoftAccountOptions() { ... }

app.UseGoogleAuthentication(googleOptions);
app.UseFacebookAuthentication(facebookOptions);
app.UseTwitterAuthentication(twitterOptions);
app.UseMicrosoftAccountAuthentication(options);

这是没有包含秘密检索代码的 Micrsoft 实现的样子。

var options = new MicrosoftAccountOptions() 
{
    ClientId = "xxxxxx", 
    ClientSecret = "xxxxxxx",
};
app.UseMicrosoftAccountAuthentication(options);

需要 nuget OpenIdConnect 扩展包:

Micrsoft.AspNetCore.Authentication.OpenIdConnect

Micrsoft.AspNetCore.Authentication.Facebook

Micrsoft.AspNetCore.Authentication.Google

Micrsoft.AspNetCore.Authentication.MicrosoftAccount

Micrsoft.AspNetCore.Authentication.Twitter

【讨论】:

    猜你喜欢
    • 2021-10-11
    • 2018-10-19
    • 2018-06-13
    • 2018-09-30
    • 2019-03-28
    • 2015-08-19
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    相关资源
    最近更新 更多