我正在尝试使用OAuth 2.0通过Sonos对ASP.NET Core Web应用程序进行身份验证。
问题在于,当尝试使用Sonos OAuth 2系统检索到的访问码访问令牌时,需要授权请求标头。
但是ASP.NET Core似乎只允许在URL内而不是在请求标头内的授权数据。尝试执行此操作时,我收到一条错误消息,提示它缺少授权标头。
Missing request header 'Authorization' for method parameter of type String
这是在通过Sonos进行身份验证之后发生的。
我的问题是:我如何使用基本授权标头作为授权数据,而不是使用请求URL中的授权数据?
我已经尝试使用以下github项目:https://github.com/blowdart/idunno.Authentication/tree/master/src/idunno.Authentication.Basic
但是对于我要实现的目标却不起作用。
我获得了与Postman一起使用的令牌的实际检索,在Postman中,我可以选择“客户端身份验证”。当我选择“发送为基本身份验证标头”时,一切正常,但是当我选择“在正文中发送客户端凭据”时,将产生上述错误。
无法正常工作并产生上述错误的代码片段:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "Sonos";
})
.AddOAuth("Sonos", options =>
{
options.ClientId = "client token generated by sonos application";
options.ClientSecret = "client secret generated by sonos application";
options.CallbackPath = new PathString("/signin-sonos");
options.AuthorizationEndpoint = "https://api.sonos.com/login/v3/oauth";
options.TokenEndpoint = "https://api.sonos.com/login/v3/oauth/access";
});
我希望OAuth授权检索到的最终访问令牌存储在我可以访问的位置,并通过Sonos API将其重新用于控制Sonos扬声器。
如果您希望重现此错误,可以在Sonos网站上创建应用程序/集成:https://integration.sonos.com/integrations