Replies: 1 comment 1 reply
-
https://api-buddy.cn/guide/script.html |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
我写了一个OAuth2 Auth Server,然后在我的resource server上需要用到我自己这个OAuth2 server产生的token, 但每次都需要copy paste有点麻烦...找了一圈没找到相对应的方法..
以下是我尝试的,但并不成功,我的secure API还是会返回401,估计是没自动导入header去
写了个Pre-request script
···
import cn.hutool.http.HttpRequest
import cn.hutool.http.HttpUtil
HttpRequest request = HttpUtil.createPost("http://localhost:9000/oauth2/token")
Map<String, Object> map = new HashMap<>();
map.put("client_id", "api-client");
map.put("client_secret", "api-secret");
map.put("scope", "apiscope");
map.put("grant_type", "client_credentials");
String result = request.form(map).execute().body();
System.out.println(result)
String token = JSON.parseObject(result).getString("access_token");
request.header("Authorization", "Bearer" +token)
···
Beta Was this translation helpful? Give feedback.
All reactions