add openapi token refresh hook

This commit is contained in:
tickstep 2024-03-02 22:10:54 +08:00
parent e8b87a02dc
commit 9dd2482b58
2 changed files with 12 additions and 6 deletions

View File

@ -133,10 +133,8 @@ doOpenLoginAct:
}, openapi.ApiToken{
AccessToken: openapiToken.AccessToken,
ExpiredAt: openapiToken.Expired,
}, func(newToken openapi.ApiToken) error {
// TODO: save & refresh new token
return nil
})
}, nil)
// open api token maybe expired
// check & refresh new one
openUserInfo, err := openPanClient.GetUserInfo()
@ -229,6 +227,14 @@ doWebLoginAct:
Workdir: "/",
WorkdirFileEntity: *aliyunpan.NewFileEntityForRootDir(),
}
u.PanClient().OpenapiPanClient().SetAccessTokenRefreshCallback(func(userId string, newToken openapi.ApiToken) error {
logger.Verboseln("openapi token refresh, update for user")
u.OpenapiToken = &PanClientToken{
AccessToken: newToken.AccessToken,
Expired: newToken.ExpiredAt,
}
return nil
})
// setup user info
name := "Unknown"

View File

@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@ -109,7 +109,7 @@ func DecryptString(text string) string {
return string(r)
}
// isFolderExist 判断文件夹是否存在
// IsFolderExist 判断文件夹是否存在
func IsFolderExist(pathStr string) bool {
fi, err := os.Stat(pathStr)
if err != nil {