修复刷新令牌

This commit is contained in:
xmdhs 2023-09-05 01:01:27 +08:00
parent 23892f19c7
commit 5c738aed9c
No known key found for this signature in database
GPG Key ID: E809D6D43DEFCC95
3 changed files with 15 additions and 3 deletions

View File

@ -26,7 +26,7 @@ type Token struct {
AccessToken string `json:"accessToken"`
AvailableProfiles []TokenProfile `json:"availableProfiles,omitempty"`
ClientToken string `json:"clientToken"`
SelectedProfile TokenProfile `json:"selectedProfile,omitempty"`
SelectedProfile TokenProfile `json:"selectedProfile"`
User TokenUser `json:"user,omitempty"`
}

View File

@ -26,7 +26,7 @@ func newYggdrasil(r *httprouter.Router, handelY yggdrasil.Yggdrasil) error {
r.POST("/api/authserver/validate", warpHJSON(handelY.Validate()))
r.POST("/api/authserver/signout", warpHJSON(handelY.Signout()))
r.POST("/api/authserver/invalidate", handelY.Invalidate())
// TODO /authserver/refresh
r.POST("/api/authserver/refresh", handelY.Refresh())
return nil
}

View File

@ -11,6 +11,7 @@ import (
"github.com/google/uuid"
"github.com/xmdhs/authlib-skin/db/ent"
"github.com/xmdhs/authlib-skin/db/ent/user"
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
"github.com/xmdhs/authlib-skin/model/yggdrasil"
sutils "github.com/xmdhs/authlib-skin/service/utils"
@ -148,11 +149,22 @@ func (y *Yggdrasil) Refresh(ctx context.Context, token yggdrasil.RefreshToken) (
if err != nil {
return yggdrasil.Token{}, fmt.Errorf("Authenticate: %w", err)
}
up, err := y.client.UserProfile.Query().Where(userprofile.UUIDEQ(t.Subject)).First(ctx)
if err != nil {
return yggdrasil.Token{}, fmt.Errorf("Authenticate: %w", err)
}
return yggdrasil.Token{
AccessToken: jwts,
ClientToken: t.CID,
SelectedProfile: yggdrasil.TokenProfile{
ID: up.UUID,
Name: up.Name,
},
User: yggdrasil.TokenUser{
ID: t.Subject,
ID: t.Subject,
Properties: []any{},
},
}, nil
}