asp.net-core - ASP.Net Core OpenIdConnect Steam

标签 asp.net-core openid steam-web-api

我正在尝试实现 Steam OpenId到我的 ASP.Net Core 应用程序中,并且我以前没有任何实现 OpenID 的经验。
不幸的是,Steam 方面严重缺乏文档,只是简单地声明“只需下载 OpenID 库”,并为您提供一个页面来注册域名的 API key 。

有几种实现可用于完整的 ASP.Net,但不适用于 Core,而且似乎存在一些差异。

我正在尝试使用 Microsoft.AspNetCore.Authentication.OpenIdConnect ,尽管我不完全确定这是否是正确的库。看来“OpenID”和“OpenID Connect”之间有区别。

我已经在 Startup.cs 中设置了身份验证,如下所示:

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    DisplayName = "Steam",
    Authority = "http://steamcommunity.com/openid",
    ClientId = "MyClientId",
    ClientSecret = "ApiKeyHere",
    SignInScheme = "SignInCookie",
    CallbackPath = new PathString("/Account/SteamCallback"),
    RequireHttpsMetadata = false
});

但是当我进入包含返回挑战的操作的登录页面时:

public IActionResult SignIn()
{
    return Challenge();
}

我收到错误

JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Newtonsoft.Json.JsonTextReader.ParseValue() InvalidOperationException:
IDX10803: Unable to obtain configuration from: 'http://steamcommunity.com/openid/.well-known/openid-configuration'.

当我查看这个 URL 时,它似乎返回了 OpenID 配置的 XML 数据:

<?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>

但是 OpenID 规范指出此信息 should be in JSON .

接下来,我尝试注册自己的 OpenIdConnectMiddleware,就像 this 一样。 ASP.Net 实现做到了这一点,但是,由于缺少 OpenIdConnectMiddleware 类所需的服务,这导致无法构建:

System.InvalidOperationException: 'A suitable constructor for type 'TestApplication.SteamOpenId.SteamAuthenticationMiddleware' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.'

我的实现:

public class SteamAuthenticationMiddleware : OpenIdConnectMiddleware
{
    public SteamAuthenticationMiddleware(
        RequestDelegate next,
        IDataProtectionProvider dataProtectionProvider,
        ILoggerFactory loggerFactory,
        UrlEncoder encoder,
        IServiceProvider services,
        IOptions<SharedAuthenticationOptions> sharedOptions,
        IOptions<OpenIdConnectOptions> options,
        HtmlEncoder htmlEncoder) :
        base(
            next,
            dataProtectionProvider,
            loggerFactory,
            encoder,
            services,
            sharedOptions,
            options,
            htmlEncoder)
    {
    }

    protected override AuthenticationHandler<OpenIdConnectOptions> CreateHandler() => new SteamAuthenticationHandler();
}

我知道这个问题不是很具体,但是有人能指出我正确的方向吗?我有点困惑。

最佳答案

It seems there is a difference between "OpenID" and "OpenID Connect".

有:OpenID 1/2 和 OpenID Connect 是完全不同的协议(protocol)。

Steam 仍在使用 OpenID 2.0,因此您无法使用 ASP.NET Core 的 OpenID Connect 中间件来使用 Steam 帐户对用户进行身份验证,因为这两个协议(protocol)不兼容/互操作。

I know this question isn't very specific, but can anyone point me in the right direction with this? I am a little stumped.

您提到的 aspnet-contrib Steam 中间件源自专门为 ASP.NET Core 开发的通用 OpenID 2.0 提供程序,因此可能是您的最佳选择(也就是说,我是编写它的人,所以我'我可能不客观)。

您可以在 NuGet.org 上找到该包:https://www.nuget.org/packages/AspNet.Security.OpenId.Steam/ .

关于asp.net-core - ASP.Net Core OpenIdConnect Steam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44487710/

相关文章:

c# - 异常处理中间件和页面

c# - 使用KeyVault存储ABP框架的默认连接字符串

c# - 如何记录自定义变量

proxy - 指定与 DotNetOpenID 一起使用的代理

api - Steam API 2020

c# - IDatabaseService 依赖注入(inject)失败?

node.js - 缺少 OpenID 标识符

azure - 如何代表流将 cookie 与 Azure AD 结合使用来获取其他资源的访问 token

steam-web-api - 如何获得所有CSGO项目的列表,包括皮肤名称,质量和稀有性?

windows - Adobe AIR 3.1 渲染/输入问题与 Steam 覆盖 (Windows)