小编Bal*_*rai的帖子

Spring Zuul Gateway Swagger-UI 适用于所有微服务

(对不起,如果我没有任何意义,已经很晚了,我似乎无法找到答案)

我们正在使用带有 netflix zuul 网关的 spring boot 微服务,我们想访问那里的所有端点列表。我们在网关上设置了 swagger-ui,我们可以卷曲微服务的 /v2/api-docs,但我们不知道如何在 swagger-ui 中显示它。

我首先尝试使用这种方法。(我是从 pastebin 链接的,因为它很长,我不知道将它包含在帖子中是否被认为是不好的做法。)
它向我展示了网关的端点,而不是微服务。它还让我从我们的身份验证服务中获取令牌。

然后我尝试了这个,实际上我从我添加的微服务中得到了 401。

@Component
@Primary
@EnableAutoConfiguration
public class SwaggerAggregatorController implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
        List<SwaggerResource> resources= new ArrayList<>();
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName("ms-name");
        swaggerResource.setLocation("/ms-name/v2/api-docs");
        swaggerResource.setSwaggerVersion("2.0");

        resources.add(swaggerResource);
        return resources;
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用 Postman 中的http://gateway/ms/v2/api-docs使用 Bearer 令牌获取 json 。
我们使用 OAuth2。当然,当我加载 swagger-ui 时,我得到了预期的结果

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}  
Run Code Online (Sandbox Code Playgroud)

所以我应该向请求添加一个不记名令牌,但我需要从使用 OAuth2 的 auth-service 获取它。我应该如何授权 swagger 以便它可以从其他微服务中获取所有资源?

再次,如果我没有任何意义,我深表歉意。 …

swagger spring-boot spring-security-oauth2 netflix-zuul

8
推荐指数
0
解决办法
3809
查看次数