Browse Source

fix 酷乐秀扫码登录

Eric 2 months ago
parent
commit
e4effb3eee

+ 8 - 1
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/service/CustomAuthenticationKeyGenerator.java

@@ -4,6 +4,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.TreeSet;
 
+import cn.hutool.core.util.RandomUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.security.oauth2.common.util.OAuth2Utils;
 import org.springframework.security.oauth2.provider.OAuth2Authentication;
@@ -25,7 +26,13 @@ public class CustomAuthenticationKeyGenerator extends DefaultAuthenticationKeyGe
 		if (!authentication.isClientOnly()) {
 			values.put(USERNAME, StringUtils.substringAfter(authentication.getName(), ":"));
 		}
-		values.put(CLIENT_ID, authorizationRequest.getClientId());
+
+		String clientId = authorizationRequest.getClientId();
+		if (StringUtils.isNotEmpty(clientId) && "qr_teacher".equalsIgnoreCase(clientId)) {
+			// 酷乐秀老师端扫码登录,允许多端登录,同时生成多个token
+			clientId += ":" + RandomUtil.randomNumbers(6);
+		}
+		values.put(CLIENT_ID, clientId);
 		if (authorizationRequest.getScope() != null) {
 			values.put(SCOPE, OAuth2Utils.formatParameterList(new TreeSet<String>(authorizationRequest.getScope())));
 		}