refactor: add GetAdminToken interface. (#2684)

* refactor: add GetAdminToken interface.

* update config.
This commit is contained in:
Monet Lee
2024-09-29 16:20:34 +08:00
committed by GitHub
parent 765fa17e7a
commit 5452741af8
8 changed files with 21 additions and 19 deletions
+4 -4
View File
@@ -87,13 +87,13 @@ func (a *Api) apiPost(ctx context.Context, path string, req any, resp any) error
return nil
}
func (a *Api) GetToken(ctx context.Context) (string, error) {
req := auth.UserTokenReq{
func (a *Api) GetAdminToken(ctx context.Context) (string, error) {
req := auth.GetAdminTokenReq{
UserID: a.UserID,
Secret: a.Secret,
}
var resp auth.UserTokenResp
if err := a.apiPost(ctx, "/auth/user_token", &req, &resp); err != nil {
var resp auth.GetAdminTokenResp
if err := a.apiPost(ctx, "/auth/get_admin_token", &req, &resp); err != nil {
return "", err
}
return resp.Token, nil
+3 -2
View File
@@ -21,7 +21,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/openimsdk/tools/errs"
"io"
"log"
"net/http"
@@ -34,6 +33,8 @@ import (
"sync/atomic"
"time"
"github.com/openimsdk/tools/errs"
"github.com/openimsdk/protocol/third"
)
@@ -95,7 +96,7 @@ func (m *Manage) Run() error {
}
var err error
ctx := context.WithValue(m.ctx, "operationID", fmt.Sprintf("%s_init", m.prefix))
m.api.Token, err = m.api.GetToken(ctx)
m.api.Token, err = m.api.GetAdminToken(ctx)
if err != nil {
return err
}