feat: 增加鉴权
This commit is contained in:
parent
ee31f328c1
commit
cc1fc2b360
2
pom.xml
2
pom.xml
@ -24,7 +24,7 @@
|
||||
<dependency>
|
||||
<groupId>group.flyfish</groupId>
|
||||
<artifactId>rest-proxy-core</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -3,6 +3,8 @@ package group.flyfish.demo.service.other;
|
||||
import group.flyfish.rest.annotation.RestApi;
|
||||
import group.flyfish.rest.annotation.RestBody;
|
||||
import group.flyfish.rest.annotation.RestService;
|
||||
import group.flyfish.rest.annotation.methods.GET;
|
||||
import group.flyfish.rest.annotation.methods.POST;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
@ -20,6 +22,6 @@ public interface OtherTestService {
|
||||
* @param body 请求体
|
||||
* @return 结果
|
||||
*/
|
||||
@RestApi(uri = "/mcp/pc/pcsearch")
|
||||
@POST("/mcp/pc/pcsearch")
|
||||
Object postPcSearch(@RestBody Object body);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package group.flyfish.demo.service.weather;
|
||||
|
||||
import group.flyfish.rest.annotation.RestApi;
|
||||
import group.flyfish.rest.annotation.RestParams;
|
||||
import group.flyfish.rest.annotation.RestService;
|
||||
import group.flyfish.rest.annotation.methods.GET;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -20,7 +20,7 @@ public interface YikeWeatherService {
|
||||
* @return 结果
|
||||
* @apiNote 使用@RestParams,框架会自动注入所有键值对作为query
|
||||
*/
|
||||
@RestApi("/day")
|
||||
@GET("/day")
|
||||
Map<String, Object> getDay(@RestParams Map<String, Object> params);
|
||||
|
||||
/**
|
||||
@ -29,6 +29,6 @@ public interface YikeWeatherService {
|
||||
* @return 结果
|
||||
* @apiNote 框架会自动将参数解包成query
|
||||
*/
|
||||
@RestApi("/day")
|
||||
@GET("/day")
|
||||
Map<String, Object> getDayStraight(String appid, String appsecret, String city);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package group.flyfish.demo.service.yapi;
|
||||
|
||||
import group.flyfish.rest.core.auth.RestAuthProvider;
|
||||
import group.flyfish.rest.core.client.RestClientBuilder;
|
||||
|
||||
/**
|
||||
* yapi调用需要的鉴权配置
|
||||
*
|
||||
* @author wangyu
|
||||
*/
|
||||
public class YapiAuthProvider implements RestAuthProvider {
|
||||
|
||||
// yapi控制token
|
||||
private static final String token = "e5172a42e62e0497b79e3c7df7b4ec1429399558f9d9d28c0152bd39ba4c217a";
|
||||
|
||||
/**
|
||||
* 通过入侵client提供鉴权
|
||||
* yapi是使用query鉴权的,所以增加query即可
|
||||
*
|
||||
* @param builder rest客户端构建器
|
||||
*/
|
||||
@Override
|
||||
public void provide(RestClientBuilder builder) {
|
||||
// 支持添加认证头的方式,在此处也可以调用其他rest服务获取接口
|
||||
// builder.addHeader("Authorization", "token")
|
||||
builder.addParam("token", token);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package group.flyfish.demo.service.yapi;
|
||||
|
||||
import group.flyfish.rest.annotation.RestService;
|
||||
|
||||
/**
|
||||
* yapi服务,支持鉴权
|
||||
*
|
||||
* @author wangyu
|
||||
*/
|
||||
@RestService(value = "yapi", authProvider = YapiAuthProvider.class)
|
||||
public interface YapiService {
|
||||
|
||||
|
||||
}
|
@ -3,4 +3,5 @@ rest:
|
||||
always-trust: true
|
||||
urls:
|
||||
other: https://ug.baidu.com
|
||||
yapi: http://yapi.flyfish.group/api
|
||||
connection-timeout: 10s
|
||||
|
Loading…
Reference in New Issue
Block a user