Alb*_*rtK 2 oauth-2.0 openid-connect aspnet-contrib asp.net-core
我试图通过此帖子用ASOS强加OpenID Connect服务器(资源所有者密码凭据授予)。当我在一个应用程序中同时拥有授权服务器和资源服务器时,一切工作正常。但是,当我在两个应用程序(但在一台机器上)上拆分它们时,资源服务器无法验证令牌并返回访问令牌无效。
我下载了的源代码AspNet.Security.OAuth.Validation
以调查此问题,并在此处返回null
以下是来自授权服务器的一些日志:
信息:Microsoft.AspNetCore.Hosting.Internal.WebHost [1] 请求启动HTTP / 1.1 POST http:// localhost:5000 / connect / token application / x-www-form-urlencoded; 字符集= UTF-8 77 信息:AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerMiddleware [0] 令牌请求已成功从HTTP请求中提取:{ “ grant_type”:“密码”, “ username”:“ UserLogin”, “ password”:“ [出于安全原因被删除]”, “ scope”:“ offline_access” }。 信息:AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerMiddleware [0] 令牌请求已成功验证。 记录:AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerMiddleware [0] 触发了登录操作:子:123,用户名:UserLogin; [.scopes,[“电子邮件”,“个人资料”,“离线访问”]],[。resources,[“ resource_server”]]。 dbug:Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository [37] 从文件'C:\ Users \ User1 \ AppData \ Local \ ASP.NET \ DataProtection-Keys \ key-********-****-****-****-中读取数据64bb57db1c3b.xml”。 dbug:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager [18] 找到了密钥{********-****-****-****-64bb57db1c3b}。 dbug:Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver [13] 将失效日期为2017-09-27 16:44:49Z的密钥{********-****-****-****-****-64bb57db1c3b}作为默认密钥。 dbug:Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor [51] 使用Windows DPAPI解密机密元素。 dbug:Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.CngCbcAuthenticatedEncryptorDescriptor [4] 使用链接方式CBC从提供者'(null)'打开CNG算法'AES'。 dbug:Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.CngCbcAuthenticatedEncryptorDescriptor [3] 使用HMAC从提供程序'(null)'打开CNG算法'SHA256'。 dbug:Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider [2] 使用密钥{********-****-****-****-64bb57db1c3b}作为默认密钥。 记录:Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector [31] 出于目的('C:\ Users \ User1 \ documents \ visual studio 2017 \ Projects)对密钥{********-****-****-****-64bb57db1c3b}执行保护操作\ OpenIdDictSample \ Aka.OpenIdConnectServer”,“ OpenIdConnectServerHandler”,“ AccessTokenFormat”,“ ASOS”)。 记录:AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerMiddleware [0] 使用指定的数据格式的新的访问令牌已成功生成:CfDJ8NSKICBGwihOm75ku1fbHDtG4usEbfF-mLGaJcGGFEPQJLb36rfHqCTJ3Clu_SCBRHlaZ_B7s3pxNfUqS9fPfjtjjEH1KKmkiV6gvakRYf0Iof32BVddUUPgd7sEDrB0fET91pIDJT9WwsPx653viw5tFyvrztsSD5CYAOQZjm1werRcVPuvwRhXUQb_9Vbba52tqj8y7WbOjk78Hl17knbwSz4C70vwlRU5pL_Bp41R4vEEKwtm_VMQ_u1kSBKM5KjOh6OKdbDJ9jOhyh4RpNbvGN25ZskzByi8ndKRW3dmajWYyf-0cj6-4MEE5Hocd47te8C-haYIxEUb7tcQ-JTItknIiE1sk6W7zHlhLg3nprE2Ct4mvKi11G7Kvd1W4u-UmEvL1NesjVFNKpNJVdEaK2I8mcNzJLU69ZnM4poRrLqEqD__cHa8nCFgPtE9L0Jyo6IyFwc7NZ2sXz7y7lPfJ9Q3Pu1W_t0lOGBte5uKHfJZpiOYaqKrAwdJSpULLK52iKoCNhRYxOSdq__DNJs; 子:123,用户名:UserLogin; [.scopes,[“ email”,“ profile”,“ offline_access”]],[.resources,[“ resource_server”]],[.issued,Fri,30 Jun 2017 09:13:29 GMT],[.expires ,星期五, 记录:Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector [31] 出于目的('C:\ Users \ User1 \ documents \ visual studio 2017 \ Projects)对密钥{********-****-****-****-64bb57db1c3b}执行保护操作\ OpenIdDictSample \ Aka.OpenIdConnectServer”,“ OpenIdConnectServerHandler”,“ RefreshTokenFormat”,“ ASOS”)。 记录:AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerMiddleware [0] 使用指定的数据格式的新更新凭证已成功生成:CfDJ8NSKICBGwihOm75ku1fbHDtcKlYz_IbJiNmiW_tfu19E7p5BIO9xE0b2qu8mYWw-zD7wCWB1F5Fx548L4FARrsJwlJls1AkK2GrqXjV0krH6me_btsSAxM9trrFCUL2ZrXkm2sStZ6DUcbf_cSNFh-YxXft-gbLGV11THAINTb8K9-v_fkeXq7aN8Qgu7zJfhON1ehflLwZ-DXZwW_S9assqx8f7oe-n5gTzOO6PjEyO5g0YMJ1SY7X-sMO1MKjn03vZxPB0ecT0l8NXB89vGhW7kZnoEaL1NwmSTiEOYMatwrkURPBgb2YLnpiu7sYAD04HxsicoLaQTDbc8ZJyWUJ7guLl6Mp2HLhZG_wLQM9REC_QeZX8eDn8aqSOiGKZeLF4G7A5y369VIZ0RPASdTpEsAHSE8ws0RB18jap-75bM_aAi3w3-PlfnY7ySnDYm3xkF1ImyBcph2XF6R8-imdAXhQG-tTAYd2FKw4msaWCPcnX5CxYlo-alVYpd878haDvo43fCvbd2_Dc2O1wI98; 子:123,用户名:UserLogin; [.scopes,[“ email”,“ profile”,“ offline_access”]],[.resources,[“ resource_server”]],[.issued,Fri,30 Jun 2017 09:13:29 GMT],[.expires ,星期五, 信息:AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerMiddleware [0] 令牌响应已成功返回:{ “ resource”:“ resource_server”, “ scope”:“电子邮件配置文件offline_access”, “ token_type”:“承载者”, “ access_token”:“ [出于安全原因被删除]”, “ expires_in”:3600, “ refresh_token”:“ [出于安全原因被删除]” }。
以下是来自资源服务器的一些日志:
信息:Microsoft.AspNetCore.Hosting.Internal.WebHost [1] 请求启动HTTP / 1.1 GET http:// localhost:5001 / api / values 记录:Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector [5] 出于目的('C:\ Users \ User1 \ documents \ visual studio 2017 \ Projects)对密钥{********-****-****-****-64bb57db1c3b}执行取消保护操作\ OpenIdDictSample \ Aka.WebApi”,“ OpenIdConnectServerHandler”,“ AccessTokenFormat”,“ ASOS”)。 dbug:Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository [37] 从文件'C:\ Users \ User1 \ AppData \ Local \ ASP.NET \ DataProtection-Keys \ key-********-****-****-****-中读取数据64bb57db1c3b.xml”。 dbug:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager [18] 找到了密钥{********-****-****-****-64bb57db1c3b}。 dbug:Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver [13] 将失效日期为2017-09-27 16:44:49Z的密钥{********-****-****-****-****-64bb57db1c3b}作为默认密钥。 dbug:Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor [51] 使用Windows DPAPI解密机密元素。 dbug:Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.CngCbcAuthenticatedEncryptorDescriptor [4] 使用链接方式CBC从提供者'(null)'打开CNG算法'AES'。 dbug:Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.CngCbcAuthenticatedEncryptorDescriptor [3] 使用HMAC从提供程序'(null)'打开CNG算法'SHA256'。 dbug:Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider [2] 使用密钥{********-****-****-****-64bb57db1c3b}作为默认密钥。 信息:AspNet.Security.OAuth.Validation.OAuthValidationMiddleware [7] 承载未认证。失败消息:身份验证失败,因为访问令牌无效。
1)我的资源服务器出了什么问题?
2)如何在不同的机器上配置资源服务器(尤其是令牌签名/检查和加密/解密)?
如何在不同的机器上配置资源服务器(尤其是令牌签名/检查和加密/解密)?
您需要确保密钥环(包含由ASP.NET Core Data Protection派生的主密钥来创建加密和验证密钥)已正确同步并由授权服务器和资源服务器共享。该过程在此处进行了描述:https : //docs.microsoft.com/zh-cn/aspnet/core/security/data-protection/configuration/overview。
这是一个如何使用共享文件夹完成此操作的示例:
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"\\server\share\directory\"))
}
Run Code Online (Sandbox Code Playgroud)
您还需要将两个应用程序配置为使用相同的“应用程序区分符”:
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"\\server\share\directory\"))
.SetApplicationName("Your application name");
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
598 次 |
最近记录: |