diff --git a/internal/app/github_auth/code.go b/internal/app/github_auth/code.go
index 7eefdce94448d842e5bfa1c83c6ac2a35e2fdb4e..4f9f046126b055817c6707c843d1aba99bd5b42a 100644
--- a/internal/app/github_auth/code.go
+++ b/internal/app/github_auth/code.go
@@ -10,10 +10,11 @@ import (
)
type ClientAuthInfo struct {
- ClientId string `json:"client_id"`
- DeviceCode string `json:"device_code"`
- UserCode string `json:"user_code"`
- CardCode string `json:"card_code"`
+ ClientId string `json:"client_id"`
+ DisplayUserName string `json:"display_user_name,omitempty"`
+ DeviceCode string `json:"device_code"`
+ UserCode string `json:"user_code"`
+ CardCode string `json:"card_code"`
}
type ClientOAuthInfo struct {
@@ -119,7 +120,7 @@ func GenDevicesCode(codeLen int) string {
}
// UpdateClientAuthStatusByDeviceCode 更新客户端授权码通过设备代码
-func UpdateClientAuthStatusByDeviceCode(deviceCode string, cardCode string) error {
+func UpdateClientAuthStatusByDeviceCode(deviceCode string, cardCode string, displayUserName string) error {
redisKey := fmt.Sprintf("copilot.proxy.map.%s", deviceCode)
uCode, err := cache.Get(redisKey)
if err != nil {
@@ -136,6 +137,9 @@ func UpdateClientAuthStatusByDeviceCode(deviceCode string, cardCode string) erro
return err
}
authInfo.CardCode = cardCode
+ if displayUserName != "" {
+ authInfo.DisplayUserName = displayUserName
+ }
authInfoData, _ = json.Marshal(authInfo)
err = cache.Set(redisKey, authInfoData, -1)
return err
diff --git a/internal/controller/auth/github.go b/internal/controller/auth/github.go
index 258eabfe8eac84214d21461c26aa06991fd83882..d8d173a6f62465fa7100265f7026ccff4bf761be 100644
--- a/internal/controller/auth/github.go
+++ b/internal/controller/auth/github.go
@@ -83,6 +83,7 @@ func postLoginOauthAccessToken(ctx *gin.Context) {
return
}
tk, _ := jwtpkg.CreateToken(&middleware.UserLoad{
+ UserDisplayName: cliAuthInfo.DisplayUserName,
CardCode: u.CardCode,
Client: cliAuthInfo.ClientId,
RegisteredClaims: jwtpkg.CreateStandardClaims(t.Unix(), "user"),
@@ -96,9 +97,10 @@ func postLoginOauthAccessToken(ctx *gin.Context) {
}
type loginDeviceRequestInfo struct {
- Code string `json:"code"`
- Authorization string `json:"authorization"`
- Password string `json:"password"`
+ Code string `json:"code"`
+ Authorization string `json:"authorization"`
+ DisplayUserName string `json:"displayUserName,omitempty"`
+ Password string `json:"password"`
}
func postLoginDevice(ctx *gin.Context) {
@@ -129,7 +131,7 @@ func postLoginDevice(ctx *gin.Context) {
return
}
- err = github_auth.UpdateClientAuthStatusByDeviceCode(authInfo.DeviceCode, info.Authorization)
+ err = github_auth.UpdateClientAuthStatusByDeviceCode(authInfo.DeviceCode, info.Authorization, info.DisplayUserName)
if err != nil {
response.FailJson(ctx, response.FailStruct{
Code: 500,
diff --git a/internal/controller/copilot/user.go b/internal/controller/copilot/user.go
index bd89c63948ef46b60dd0e33de785869ad7ccbbf0..3e4b33e1f78ef4dc499792d33f6601a10a983599 100644
--- a/internal/controller/copilot/user.go
+++ b/internal/controller/copilot/user.go
@@ -3,12 +3,19 @@ package copilot
import (
"github.com/gin-gonic/gin"
"net/http"
+ "ripper/internal/middleware"
+ jwtpkg "ripper/pkg/jwt"
)
func getLoginUser(ctx *gin.Context) {
+ userDisplayName := "github"
+ token, _ := jwtpkg.GetJwtProto(ctx, &middleware.UserLoad{})
+ if token != nil && token.UserDisplayName != "" {
+ userDisplayName = token.UserDisplayName
+ }
ctx.Header("X-OAuth-Scopes", "gist, read:org, repo, user, workflow, write:public_key")
ctx.JSON(http.StatusOK, gin.H{
- "login": "github",
+ "login": userDisplayName,
"id": 9919,
"node_id": "DEyOk9yZ2FuaXphdGlvbjk5MTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/9919?v=4",
diff --git a/internal/middleware/jwt_model.go b/internal/middleware/jwt_model.go
index 862b2607e6bbf92fabffba578bf14c01db08bcb1..9390d2e49773d3b2053287558a97c82f99def57b 100644
--- a/internal/middleware/jwt_model.go
+++ b/internal/middleware/jwt_model.go
@@ -10,8 +10,9 @@ type AdminLoad struct {
}
type UserLoad struct {
- CardCode string `json:"token"`
- Client string `json:"client"`
+ UserDisplayName string `json:"userDisplayName,omitempty"`
+ CardCode string `json:"token"`
+ Client string `json:"client"`
jwt.RegisteredClaims
}
diff --git a/static/public/code.html b/static/public/code.html
index 758ba993a8e2a7775306db0cc33e72efab301e46..22a79fee8391a008bb2fd8bef209d5b8150ed196 100644
--- a/static/public/code.html
+++ b/static/public/code.html
@@ -33,7 +33,7 @@
margin: 0.5em 0;
border: 1px solid #ccc;
border-radius: 5px;
- box-sizing: border-box; /* 确保填充和边框包含在宽度和高度中 */
+ box-sizing: border-box; /* 确保填充和边框包含在宽度和���度中 */
font-size: 16px;
}
@@ -108,6 +108,8 @@
placeholder="请输入访问密码, 在环境变量LOGIN_PASSWORD参数中">
+
@@ -144,6 +146,7 @@
event.preventDefault();
const authorization = document.getElementById('authorization').value;
const password = document.getElementById('password').value;
+ const displayUserName = document.getElementById('displayUserName').value;
const code = getQueryParam('user_code');
if (code === null) {
@@ -162,7 +165,12 @@
headers: {
'Content-Type': 'application/json'
},
- body: JSON.stringify({code, authorization, password})
+ body: JSON.stringify({
+ code,
+ authorization,
+ password,
+ displayUserName
+ })
})
if (!response.ok) {