From f65443d8abeaedc9d102324565e8368e7c9d90c8 Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: 星期一, 19 六月 2023 14:41:54 +0800
Subject: [PATCH] commit

---
 src/main/java/com/gk/firework/Config/Oauth2/JwtAccessToken.java |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/gk/firework/Config/Oauth2/JwtAccessToken.java b/src/main/java/com/gk/firework/Config/Oauth2/JwtAccessToken.java
new file mode 100644
index 0000000..87c0f7c
--- /dev/null
+++ b/src/main/java/com/gk/firework/Config/Oauth2/JwtAccessToken.java
@@ -0,0 +1,26 @@
+package com.gk.firework.Config.Oauth2;
+
+import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
+import org.springframework.security.oauth2.common.OAuth2AccessToken;
+import org.springframework.security.oauth2.provider.OAuth2Authentication;
+import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
+
+/**
+ * 自定义token
+ *
+ * @author zhangby
+ * @date 2019-04-01 11:39
+ */
+public class JwtAccessToken extends JwtAccessTokenConverter {
+
+    @Override
+    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
+        DefaultOAuth2AccessToken defaultOAuth2AccessToken = new DefaultOAuth2AccessToken(accessToken);
+        // 设置额外用户信息
+        OauthUser baseUser = ((OauthUser) authentication.getPrincipal());
+        // 将用户信息添加到token额外信息中
+        defaultOAuth2AccessToken.getAdditionalInformation().put("user_id", baseUser.getId());
+
+        return super.enhance(defaultOAuth2AccessToken, authentication);
+    }
+}

--
Gitblit v1.9.2