简体   繁体   English

ASP.Net核心OpenIdConnect Steam

[英]ASP.Net Core OpenIdConnect Steam

I'm trying to implement Steam OpenId into my ASP.Net Core application, and I don't have any previous experience implementing OpenID. 我正在尝试将Steam OpenId实现到我的ASP.Net Core应用程序中,而且我之前没有任何实现OpenID的经验。
Unfortunately, Steam is massively lacking documentation on their side, and simply state "just download an OpenID library", and provide you with a page to register an API key for a domain name. 不幸的是,Steam大量缺乏文档,只是说“只需下载一个OpenID库”,并为您提供一个页面来注册域名的API密钥。

There are several implementations available for full ASP.Net, but not for Core, and it seems there are some differences. 有几种实现可用于完整的ASP.Net,但不适用于Core,似乎存在一些差异。

I'm trying to use Microsoft.AspNetCore.Authentication.OpenIdConnect , though I am not entirely sure if this is the right library. 我正在尝试使用Microsoft.AspNetCore.Authentication.OpenIdConnect ,但我不完全确定这是否是正确的库。 It seems there is a difference between "OpenID" and " OpenID Connect ". 似乎“OpenID”和“ OpenID Connect ”之间存在差异。

I've set up the authentication in my Startup.cs like so: 我在我的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
});

But as soon as I hit the sign-in page, which consists of an action returning a challenge: 但只要我点击登录页面,其中包含一个返回挑战的操作:

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

I get the error 我收到了错误

JsonReaderException: Unexpected character encountered while parsing value: <. JsonReaderException:解析值时遇到意外的字符:<。 Path '', line 0, position 0. 路径'',第0行,第0位。
Newtonsoft.Json.JsonTextReader.ParseValue() InvalidOperationException: Newtonsoft.Json.JsonTextReader.ParseValue()InvalidOperationException:
IDX10803: Unable to obtain configuration from: ' http://steamcommunity.com/openid/.well-known/openid-configuration '. IDX10803:无法从以下位置获取配置:' http ://steamcommunity.com/openid/.well-known/openid-configuration'。

When I look at this URL, it seems to return XML data for the configuration of OpenID: 当我查看此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>

But the OpenID spec states that this info should be in JSON . 但OpenID规范声明此信息应为JSON

Next I tried registering my own OpenIdConnectMiddleware , much like how this ASP.Net implemtation does it, however, this resulted in not being able to be constructed due to missing services that the OpenIdConnectMiddleware class requires: 接下来我尝试注册我自己的OpenIdConnectMiddleware ,就像这个 ASP.Net实现的方式一样,但是,由于缺少OpenIdConnectMiddleware类所需的服务,导致无法构建它:

System.InvalidOperationException: 'A suitable constructor for type 'TestApplication.SteamOpenId.SteamAuthenticationMiddleware' could not be located. System.InvalidOperationException:'无法找到类型'TestApplication.SteamOpenId.SteamAuthenticationMiddleware'的合适构造函数。 Ensure the type is concrete and services are registered for all parameters of a public constructor.' 确保类型是具体的,并为公共构造函数的所有参数注册服务。

My implementation: 我的实施:

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();
}

I know this question isn't very specific, but can anyone point me in the right direction with this? 我知道这个问题不是很具体,但有人能指出我正确的方向吗? I am a little stumped. 我有点难过。

It seems there is a difference between "OpenID" and "OpenID Connect". 似乎“OpenID”和“OpenID Connect”之间存在差异。

There is: OpenID 1/2 and OpenID Connect are totally different protocols. 有:OpenID 1/2和OpenID Connect是完全不同的协议。

Steam is still using OpenID 2.0 so you can't use ASP.NET Core's OpenID Connect middleware to authenticate your users using their Steam account, as the two protocols are not compatible/interoperable. Steam仍在使用OpenID 2.0,因此您无法使用ASP.NET Core的OpenID Connect中间件来使用其Steam帐户对您的用户进行身份验证,因为这两个协议不兼容/可互操作。

I know this question isn't very specific, but can anyone point me in the right direction with this? 我知道这个问题不是很具体,但有人能指出我正确的方向吗? I am a little stumped. 我有点难过。

The aspnet-contrib Steam middleware you've mentioned derives from a generic OpenID 2.0 provider specially developed for ASP.NET Core and thus is probably your best option (that said, I'm the guy who's written it, so I'm likely not objective). 您提到的aspnet-contrib Steam中间件来自专为ASP.NET Core开发的通用OpenID 2.0提供程序,因此可能是您的最佳选择(也就是说,我是那个写它的人,所以我可能不会目的)。

You can find the package on NuGet.org: https://www.nuget.org/packages/AspNet.Security.OpenId.Steam/ . 您可以在NuGet.org上找到该软件包: https ://www.nuget.org/packages/AspNet.Security.OpenId.Steam/。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使 Asp.Net Core Identity 与 OpenIdConnect 一起工作 - How to make Asp.Net Core Identity to work with OpenIdConnect ASP.NET 核心 OpenIdConnect 和管理员同意同一回调路径 - ASP.NET Core OpenIdConnect and admin consent on the same callback path 关闭asp.net mvc core 2 OpenIdConnect中的AutomaticChallenge - Turn off AutomaticChallenge in asp.net mvc core 2 OpenIdConnect 不能在asp.net core 2.0中使用CookieAuthenticaton和openidConnect身份验证 - Cannot use CookieAuthenticaton and openidConnect Authentication in asp.net core 2.0 ASP.NET 核心 3.1 OpenIDConnect 消息。state 是 null - ASP.NET Core 3.1 OpenIDConnect message.state is null ADAL 在 ASP Net Core 中与 OpenIdConnect 一起使用吗 - Is ADAL used in ASP Net Core with OpenIdConnect ASP.NET 5 OpenIdConnect刷新令牌 - ASP.NET 5 OpenIdConnect Refresh_Token Azure AD OpenIDConnect + ASP.NET Core-身份验证和额外权限/令牌? - Azure AD OpenIDConnect + ASP.NET Core - Authenticate and Extra Permissions/Token? Blazor WebAssembly 中的 OpenIDConnect,带有 IdentityServer4 + ASP.NET Core Identity postgresql 数据库,无需重定向 - OpenIDConnect in Blazor WebAssembly with an IdentityServer4 + ASP.NET Core Identity postgresql database without redirect 如何使用OpenIdConnect身份验证登录ASP.NET Core身份用户? - How to sign in ASP.NET Core Identity User, using OpenIdConnect Authentication?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM