代码拉取完成,页面将自动刷新
如题,按照官方Authorize 配置的说明,forPaths
中无论怎么设置,都相当于是全量接口,这样就会造成不知道哪些接口不需要Authorize信息。。。
建议在所有接口上添加需要Authorize或不需要Authorize的标识,就像Swagger-UI一样有一把锁,比较直观
private List<SecurityContext> securityContexts() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverywhere");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
SecurityReference securityReference = new SecurityReference(Constants.ACCESS_TOKEN_KEY, authorizationScopes);
//比如这里,我这样设置以后,还是所有接口都需要认证
return Collections.singletonList(
SecurityContext.builder()
.securityReferences(Collections.singletonList(securityReference))
.forPaths(PathSelectors.regex(".*create-captcha.*"))
.build()
);
}
按以下配置后,获取验证码的接口要求填写AccessToken:
但其它的接口也需要AccessToken:
在配置了上面的forPaths后,Swagger-UI中,接口上会有一个解锁和上锁的标志,说明接口需要先授权。但Knife4J中就不知道是否需要授权。就像这种效果: