chore: use userinfoCtx
This commit is contained in:
parent
759cc3ead5
commit
77354aec52
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue