chore: use userinfoCtx

This commit is contained in:
Nya Candy 2023-01-25 11:05:04 +08:00
parent 759cc3ead5
commit 77354aec52
No known key found for this signature in database
GPG Key ID: 8B1BE5E86F2E66AE
4 changed files with 13 additions and 13 deletions

View File

@ -70,9 +70,9 @@ func ConsentCheck(ctx *gin.Context) {
// Retrieve context
global.Logger.Debugf("Retrieving context...")
var acceptCtx types.SessionContext
var userinfoCtx types.SessionContext
sessKey = fmt.Sprintf(consts.REDIS_KEY_SHARE_CONTEXT, *consentReq.Subject)
acceptCtxBytes, err := global.Redis.Get(context.Background(), sessKey).Bytes()
userinfoCtxBytes, err := global.Redis.Get(context.Background(), sessKey).Bytes()
if err != nil {
global.Logger.Errorf("Failed to retrieve context with error: %v", err)
ctx.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{
@ -82,7 +82,7 @@ func ConsentCheck(ctx *gin.Context) {
}
global.Logger.Debugf("Decoding context...")
err = json.Unmarshal(acceptCtxBytes, &acceptCtx)
err = json.Unmarshal(userinfoCtxBytes, &userinfoCtx)
if err != nil {
global.Logger.Errorf("Failed to parse context with error: %v", err)
ctx.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{
@ -94,7 +94,7 @@ func ConsentCheck(ctx *gin.Context) {
// Show the consent UI
global.Logger.Debugf("Rendering consent UI...")
templateFields := gin.H{
"user": acceptCtx.User,
"user": userinfoCtx.User,
"challenge": oauth2challenge,
"csrf": csrf,
}

View File

@ -82,9 +82,9 @@ func ConsentConfirm(ctx *gin.Context) {
global.Logger.Debugf("User accepted the request, reporting back to hydra...")
// Retrieve context
global.Logger.Debugf("Retrieving context...")
var acceptCtx types.SessionContext
var userinfoCtx types.SessionContext
sessKey = fmt.Sprintf(consts.REDIS_KEY_SHARE_CONTEXT, *consentReq.Subject)
acceptCtxBytes, err := global.Redis.Get(context.Background(), sessKey).Bytes()
userinfoCtxBytes, err := global.Redis.Get(context.Background(), sessKey).Bytes()
if err != nil {
global.Logger.Errorf("Failed to retrieve context with error: %v", err)
ctx.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{
@ -94,7 +94,7 @@ func ConsentConfirm(ctx *gin.Context) {
}
global.Logger.Debugf("Decoding context...")
err = json.Unmarshal(acceptCtxBytes, &acceptCtx)
err = json.Unmarshal(userinfoCtxBytes, &userinfoCtx)
if err != nil {
global.Logger.Errorf("Failed to parse context with error: %v", err)
ctx.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{

View File

@ -66,7 +66,7 @@ func MisskeyAuthCallback(ctx *gin.Context) {
userid := fmt.Sprintf("%s@%s", usermeta.User.Username, config.Config.Misskey.Instance)
// Save context into redis
acceptCtxBytes, err := json.Marshal(&types.SessionContext{
userinfoCtxBytes, err := json.Marshal(&types.SessionContext{
MisskeyToken: usermeta.AccessToken,
User: usermeta.User,
})
@ -78,7 +78,7 @@ func MisskeyAuthCallback(ctx *gin.Context) {
return
}
sessKey = fmt.Sprintf(consts.REDIS_KEY_SHARE_CONTEXT, userid)
err = global.Redis.Set(context.Background(), sessKey, acceptCtxBytes, consts.TIME_LOGIN_SESSION_VALID).Err()
err = global.Redis.Set(context.Background(), sessKey, userinfoCtxBytes, consts.TIME_LOGIN_SESSION_VALID).Err()
if err != nil {
global.Logger.Errorf("Failed to save session into redis with error: %v", err)
ctx.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{

View File

@ -49,9 +49,9 @@ func UserInfo(ctx *gin.Context) {
// Retrieve context
global.Logger.Debugf("Retrieving context...")
var acceptCtx types.SessionContext
var userinfoCtx types.SessionContext
sessKey := fmt.Sprintf(consts.REDIS_KEY_SHARE_CONTEXT, *tokenInfo.Sub)
acceptCtxBytes, err := global.Redis.Get(context.Background(), sessKey).Bytes()
userinfoCtxBytes, err := global.Redis.Get(context.Background(), sessKey).Bytes()
if err != nil {
global.Logger.Errorf("Failed to retrieve context with error: %v", err)
ctx.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{
@ -61,7 +61,7 @@ func UserInfo(ctx *gin.Context) {
}
global.Logger.Debugf("Decoding context...")
err = json.Unmarshal(acceptCtxBytes, &acceptCtx)
err = json.Unmarshal(userinfoCtxBytes, &userinfoCtx)
if err != nil {
global.Logger.Errorf("Failed to parse context with error: %v", err)
ctx.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{
@ -71,7 +71,7 @@ func UserInfo(ctx *gin.Context) {
}
ctx.JSON(http.StatusOK, UserinfoResponse{
MisskeyUser: acceptCtx.User,
MisskeyUser: userinfoCtx.User,
EMail: *tokenInfo.Sub,
})