From 66a68c4ead533b7a954b1735ab4947779f834090 Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Tue, 23 Jul 2019 21:19:04 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20=E9=87=8D=E8=BD=BD=20AuthState=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E9=80=82=E9=85=8D=20justauth-spring?= =?UTF-8?q?-boot-starter=20=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/zhyd/oauth/utils/AuthState.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main/java/me/zhyd/oauth/utils/AuthState.java b/src/main/java/me/zhyd/oauth/utils/AuthState.java index 948ac96..1ca1b70 100644 --- a/src/main/java/me/zhyd/oauth/utils/AuthState.java +++ b/src/main/java/me/zhyd/oauth/utils/AuthState.java @@ -51,6 +51,17 @@ public class AuthState { return create(source, RandomUtil.randomString(4)); } + /** + * 创建state + * + * @param source oauth平台 + * @param body 希望加密到state的消息体 + * @return state + */ + public static String create(AuthSource source, Object body) { + return create(source, JSON.toJSONString(body)); + } + /** * 创建state * @@ -62,6 +73,17 @@ public class AuthState { return create(source, JSON.toJSONString(body)); } + /** + * 创建state + * + * @param source oauth平台 + * @param body 希望加密到state的消息体 + * @return state + */ + public static String create(AuthSource source, String body) { + return create(source.name(), body); + } + /** * 创建state * @@ -87,6 +109,16 @@ public class AuthState { return state; } + /** + * 获取state + * + * @param source oauth平台 + * @return state + */ + public static String get(AuthSource source) { + return get(source.name()); + } + /** * 获取state * @@ -101,6 +133,19 @@ public class AuthState { return stateBucket.get(key); } + /** + * 获取state中保存的body内容 + * + * @param source oauth平台 + * @param state 加密后的state + * @param clazz body的实际类型 + * @param 需要转换的具体的class类型 + * @return state + */ + public static T getBody(AuthSource source, String state, Class clazz) { + return getBody(source.name(), state, clazz); + } + /** * 获取state中保存的body内容 * -- GitLab