diff --git a/src/main/java/me/zhyd/oauth/utils/AuthState.java b/src/main/java/me/zhyd/oauth/utils/AuthState.java index 948ac964164be7df9d6bb109d78a1bc483cf180a..1ca1b70f3915ffb346159e49109065e0239cbdc4 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内容 *