【问题标题】:OAuth validation fails for valid token in wso2 IS 4.6wso2 IS 4.6 中有效令牌的 OAuth 验证失败
【发布时间】:2017-11-23 13:57:36
【问题描述】:

我尝试通过使用 wso2 身份服务器 4.6 创建自定义处理程序来保护 rest API,即使对于有效令牌,它也会显示无效令牌。 (stub.validate(dto).getValid() always false) 但它在 IS 4.5 中运行良好。原因是什么? 请帮忙..

登录 IS 4.6

[2013-12-31 09:38:21,625] DEBUG {org.wso2.carbon.identity.oauth2.OAuth2Service} -  Access Token Request Received with the Client Id : jjTDKDAThDSg_IroxfpC4qjPCR8a, Grant Type : password
[2013-12-31 09:38:21,625] DEBUG {org.wso2.carbon.identity.oauth2.util.OAuth2Util} -  Client credentials were available in the cache for client id : jjTDKDAThDSg_IroxfpC4qjPCR8a
[2013-12-31 09:38:21,626] DEBUG {org.wso2.carbon.identity.oauth2.util.OAuth2Util} -  Successfully authenticated the client with client id : jjTDKDAThDSg_IroxfpC4qjPCR8a
[2013-12-31 09:38:21,646] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.grant.PasswordGrantHandler} -  Token request with Password Grant Type received. Username : admin@carbon.superScope : , Authentication State : true
[2013-12-31 09:38:21,647] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.grant.AbstractAuthorizationGrantHandler} -  Access Token info retrieved from the cache and served to client with client id : jjTDKDAThDSg_IroxfpC4qjPCR8a
[2013-12-31 09:38:21,647] DEBUG {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer} -  Access Token issued to client. client-id=jjTDKDAThDSg_IroxfpC4qjPCR8a user-name=admin@carbon.super to application=sample
[2013-12-31 09:38:21,721]  INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'admin@carbon.super [-1234]' logged in at [2013-12-31
 09:38:21,721+0530]
[2013-12-31 09:38:21,723] DEBUG {org.wso2.carbon.identity.oauth2.validators.TokenValidationHandler} -  Access token identifier is not present in the validation request
[2013-12-31 09:38:21,740]  INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'admin@carbon.super [-1234]' logged in at [2013-12-31
 09:38:21,740+0530]
DEBUG {org.wso2.carbon.identity.oauth2.validators.TokenValidationHandler} -  Access token identifier is not present in the validation request

登录 IS 4.5

[2013-12-31 09:48:47,432] DEBUG {org.wso2.carbon.identity.oauth2.OAuth2Service}
-  Access Token Request Received with the Client Id : jjTDKDAThDSg_IroxfpC4qjPCR8a, Grant Type : password
[2013-12-31 09:48:47,442] DEBUG {org.wso2.carbon.identity.oauth2.util.OAuth2Util} -  Client credentials were available in the cache for client id : jjTDKDAThDSg_IroxfpC4qjPCR8a
[2013-12-31 09:48:47,442] DEBUG {org.wso2.carbon.identity.oauth2.util.OAuth2Util} -  Successfully authenticated the client with client id : jjTDKDAThDSg_IroxfpC4qjPCR8a
[2013-12-31 09:48:47,462] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.grant.PasswordGrantHandler} -  Token request with Password Grant Type received.
Username : admin@carbon.superScope : , Authentication State : true
[2013-12-31 09:48:47,462] DEBUG {org.wso2.carbon.identity.oauth2.token.handlers.grant.AbstractAuthorizationGrantHandler} -  Access Token info retrieved from the cache and served to client with client id : jjTDKDAThDSg_IroxfpC4qjPCR8a
[2013-12-31 09:48:47,462] DEBUG {org.wso2.carbon.identity.oauth2.token.AccessTokenIssuer} -  Access Token issued to client. client-id=jjTDKDAThDSg_IroxfpC4qjPCR8a user-name=admin@carbon.super to application=sample
[2013-12-31 09:48:47,582]  INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'admin@carbon.super [-1234]' logged in at [2013-12-31 09:48:47,582+0530]
[2013-12-31 09:48:47,582] DEBUG {org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService} -  Token validation request received for : Client Id : nullTokenType : bearer
[2013-12-31 09:48:47,582] DEBUG {org.wso2.carbon.identity.oauth2.validators.BearerTokenValidator} -  Started processing token validation request of type : bearer
[2013-12-31 09:48:47,612]  INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'admin@carbon.super [-1234]' logged in at [2013-12-31 09:48:47,612+0530]
[2013-12-31 09:48:47,612] DEBUG {org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService} -  Token validation request received for : Client Id : nullTokenType : bearer
[2013-12-31 09:48:47,612] DEBUG {org.wso2.carbon.identity.oauth2.validators.BearerTokenValidator} -  Started processing token validation request of type : bearer

【问题讨论】:

  • 服务器控制台上是否打印了与此相关的任何调试/警告/错误日志?如果没有,假设您使用的是 OAuth2.0,请尝试通过在 /repository/conf/log4j.properties 文件中添加以下行来启用日志记录: log4j.logger.org.wso2.carbon.identity.oauth2=TRACE 您'必须重新启动服务器才能使其生效。
  • 是的,我做了同样的事情并得到以下调试消息:DEBUG {org.wso2.carbon.identity.oauth2.validators.TokenValidationHandler} - 验证请求中不存在访问令牌标识符
  • 我已经用 IS 4.5 和 4.6 中的日志更新了问题..请通过.....

标签: oauth wso2 wso2esb wso2is


【解决方案1】:

我在通过 Oauth2 验证 Web 服务访问 Wso2 Identity Server 4.6.0 的 Wso2 ESB 4.8.0 中的 OAuth Mediator 遇到了同样的问题。使用 Identity server 4.5.0 可以正常工作。中介代码调用客户端存根,将 accessToken 作为纯字符串传递。

验证服务返回的错误信息是Access token identifier is not present in the validation request

要回答您的问题,您应该使用 4.2.2 版中的捆绑包 org.wso2.carbon.identity.oauth.stub。它定义了一个类org.wso2.carbon.identity.oauth2.stub.dto.OAuth2TokenValidationRequestDTO_OAuth2AccessToken,它应该用作OAuth2TokenValidationRequestDTO.setAccessToken 方法的参数。 dto 对象可以用作OAuth2TokenValidationServiceStub.validate 方法的参数。

【讨论】:

  • 感谢您的信息....我尝试使用您提到的捆绑包,但我无法将 OAuth2TokenValidationRequestDTO_OAuth2AccessToken 对象作为 OAuth2TokenValidationRequestDTO.setAccessToken 方法的参数传递,它需要一个字符串变量。请回复
  • 旧版本的“org.wso2.carbon.identity.oauth.stub”定义了“setAccessToken(String)”方法。也许您仍在使用与“org.wso2.carbon.identity.oauth.server”捆绑版本不匹配的旧版本存根。请确保您使用的是 4.2.2。
  • 当您使用 ESB 4.8.0 时,您能回答这个question吗?
【解决方案2】:

您可能知道,OAuth 访问令牌是通过在 Identity Server 中调用 OAuth2TokenValidationService Web 服务来验证的。您能否使用 SOAPUI 试用此服务并查看... 可以在 (https://{ip}:{port}/services/OAuth2TokenValidationService?wsdl) 找到 WSDL。通常,当发送到此服务的 Web 服务请求中不存在访问令牌时会生成此错误。

在请求消息正文中,必须如下..

        <xsd1:accessToken>
           <xsd1:identifier>35d1538940ce9a1e86c0a287c521d14</xsd1:identifier>
           <xsd1:tokenType>bearer</xsd1:tokenType>
        </xsd1:accessToken>

在您的代码中,“dto”对象可能没有正确设置标识符值。

另外,请从here 中找到示例 OAuth 令牌验证客户端代码

【讨论】:

  • Hi...Asela... 服务中存在访问令牌,但它需要访问令牌中的标识符值。我比较了 IS 4.6 和 4.5 中的 jar org.wso2.carbon.identity.oauth_4.2.2.jar 发现 IS 4.5 中的访问令牌只是一个字符串变量,但在 IS 4.6 中访问令牌是一个对象,它需要一个该对象中的标识符值。如何将标识符值设置为访问令牌???
  • 是的..我尝试使用 SOAP UI 和这个 OAuth 令牌验证客户端 svn.wso2.org/repos/wso2/people/asela/oauth/validation/client 两者都可以正常工作。我猜你正在尝试存根类?我看到“OAuth2TokenValidationRequestDTO”类包含一些带有“OAuth2AccessToken”对象的内部类。有时这可能会导致该问题不适用于生成的存根。 svn.wso2.org/repos/wso2/carbon/platform/branches/turing/…
  • 是的,,,, 这里我创建了两个对象,一个外部类对象和一个内部类对象。我可以为 OAuth2AccessToken 对象(即内部类对象)设置一个标识符值。但是现在存根中的 validate 方法不能将当前的 dto 对象作为参数。我该如何解决这个问题?
猜你喜欢
  • 2019-06-14
  • 1970-01-01
  • 2014-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-30
相关资源
最近更新 更多