【问题标题】:Running JHipster microservices with Amazon Cognito使用 Amazon Cognito 运行 JHipster 微服务
【发布时间】:2020-03-04 12:29:36
【问题描述】:

我按照以下指南使用 Amazon Cognito 设置 JHipster 生成的网关:https://blog.ippon.tech/aws-cognito-and-jhipster-for-the-love-of-oauth-2-0/

我的网关运行良好,我可以使用 Cognito 登录到管理模块,但是我无法调用任何微服务。任何尝试都会遇到以下错误:

java.lang.NullPointerException: null at com.test.security.oauth2.AudienceValidator.validate(AudienceValidator.java:26) 在 com.test.security.oauth2.AudienceValidator.validate(AudienceValidator.java:13) 在 org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator.validate(DelegatingOAuth2TokenValidator.java:67) 在 org.springframework.security.oauth2.jwt.NimbusJwtDecoder.validateJwt(NimbusJwtDecoder.java:165) 在 org.springframework.security.oauth2.jwt.NimbusJwtDecoder.decode(NimbusJwtDecoder.java:126) 在 org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.authenticate(

调试显示以下代码中的受众变量为空:

public OAuth2TokenValidatorResult validate(Jwt jwt) {
    List<String> audience = jwt.getAudience();
    if (audience.stream().anyMatch(allowedAudience::contains)) {
        return OAuth2TokenValidatorResult.success();
    } else {
        log.warn("Invalid audience: {}", audience);
        return OAuth2TokenValidatorResult.failure(error);
    }
}

我已经使用以下内容配置了微服务的 application.xml:

  security:
    oauth2:
      client:
        provider:
          oidc:
            issuer-uri: https://cognito-idp.us-east-1.amazonaws.com/[secret]
        registration:
          oidc:
            client-id: [secret]
            client-secret: [secret]

是否有人能够使用 Amazon Cognito 成功运行 jHipster 生成的微服务平台?任何帮助将不胜感激。

【问题讨论】:

    标签: jhipster amazon-cognito jhipster-gateway


    【解决方案1】:

    AWS Cognito 不包括访问令牌中的受众,因此必须更新 validate 方法。

    更多详情可以在这里找到:https://github.com/Falydoor/cognito-jhipster/issues/1#issuecomment-594753033

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 1970-01-01
      • 2018-01-10
      • 2018-01-02
      • 2016-11-22
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2018-03-29
      相关资源
      最近更新 更多