我试图实现Steam OpenId到我的ASP.Net核心应用程序,我没有任何以前的经验实施OpenID。
不幸的是,Steam大量缺乏相关文档,只是简单地声明“只需下载一个OpenID库”,并为您提供一个页面来注册一个域名的API密钥。ASP.Net核心OpenIdConnect蒸汽
有几种实现可用于完整的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:<:分析值意外字符遇到。路径'',第0行,位置0.
Newtonsoft.Json.JsonTextReader.ParseValue()InvalidOperationException:
IDX10803:无法从:'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 implemtation是怎么做的,然而,这导致了不能够构建由于缺少服务的OpenIdConnectMiddleware
类要求:
System.InvalidOperationException:'类型 'TestApplication.SteamOpenId.SteamAuthenticationMiddleware'的合适构造函数不能位于 。确保类型是具体的,服务注册为公共构造函数的所有参数 '。
我的实现:
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();
}
我知道这个问题是不是很具体,但任何人都可以点我这个方向是正确的?我有点难过。
啊!我应该搜索预发布软件包。我可以发誓我尝试过这样的一个,它不针对.NET标准。谢谢,我现在就试试看!我觉得有点愚蠢。 –
谢谢你,供应商完美的作品:) –
@RenéSackers不错!很高兴它对你有效 ;) – Pinpoint