如何在 ASP.NET Core 2 中为 Steam 配置 OpenID Connect?

How can I configure an OpenID Connect for Steam in ASP.NET Core 2?

我正在尝试使用 ASP.Net Core 2 通过 Steam API 对用户进行身份验证和登录。

我的成功有限。我想我需要以下参数:

    providerURL: 'http://steamcommunity.com/openid',
    stateless: true,
    // How the OpenID provider should return the client to us
    returnURL: 'http://localhost:4000/auth/openid/return',
    realm: 'http://localhost:4000/',

我正在尝试通过 AddOpenIDConnect 机制添加身份验证。

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

        services.AddAuthentication().AddOpenIdConnect(steamOptions =>
        {
            steamOptions.ClientId = "<APIKEY>";
            steamOptions.ClaimsIssuer = "https://steamcommunity.com/openid";
        }

这行不通。显然,必须有更好的方法来调用它。

我遇到的一件值得注意的事情:Postman returns 和 XML 文件的 GET 请求:

<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
<XRD>
    <Service priority="0">
        <Type>http://specs.openid.net/auth/2.0/server</Type>
        <URI>https://steamcommunity.com/openid/login</URI>
    </Service>
</XRD>
</xrds:XRDS>

有什么方法可以强制 services.AddAuthentication() 解析 XML?

我用 Kévin Chalet 最近建造的 AspNet.Security.OpenID.Steam library 解决了这个问题。 ASP.Net Core 2.

你需要使用 2.0.0-rc2-final

您需要做的就是将 services.AddAuthentication().AddSteam() 添加到 ConfigureServices 中,就像这样(它不是那里唯一的服务):

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication().AddSteam();
}

请注意,您需要安装由 Asp.Net Core 2 Web MVC 模板和身份生成的其他默认服务。