Files
open-im-server/internal/api/auth.go
T

50 lines
1.2 KiB
Go
Raw Normal View History

2023-02-28 14:20:26 +08:00
package api
2021-12-27 18:22:32 +08:00
import (
"context"
2023-03-17 11:41:20 +08:00
2023-03-17 11:27:34 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
2023-03-16 10:46:06 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
2023-05-16 12:17:43 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
2022-08-07 22:37:27 +08:00
"github.com/gin-gonic/gin"
2023-05-29 18:04:22 +08:00
"google.golang.org/grpc"
2021-12-27 18:22:32 +08:00
)
2023-06-02 20:52:16 +08:00
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
2023-06-07 15:06:50 +08:00
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
// if err != nil {
// panic(err)
// }
return &Auth{discov: discov}
2021-12-27 18:22:32 +08:00
}
2023-02-28 11:38:05 +08:00
type Auth struct {
2023-06-01 18:36:20 +08:00
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
2023-02-28 11:38:05 +08:00
}
2021-12-27 18:22:32 +08:00
2023-05-08 12:39:45 +08:00
func (o *Auth) client(ctx context.Context) (auth.AuthClient, error) {
2023-06-01 18:36:20 +08:00
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImAuthName)
if err != nil {
return nil, err
}
return auth.NewAuthClient(c), nil
2021-12-27 18:22:32 +08:00
}
2022-05-10 09:45:55 +08:00
2023-03-02 14:41:59 +08:00
func (o *Auth) UserRegister(c *gin.Context) {
2023-03-03 18:59:28 +08:00
//a2r.Call(auth.AuthClient.UserRegister, o.client, c) // todo
2022-05-10 09:45:55 +08:00
}
2022-06-06 20:39:45 +08:00
2023-03-02 14:41:59 +08:00
func (o *Auth) UserToken(c *gin.Context) {
a2r.Call(auth.AuthClient.UserToken, o.client, c)
2023-02-28 11:38:05 +08:00
}
2022-06-07 11:42:15 +08:00
2023-03-02 14:41:59 +08:00
func (o *Auth) ParseToken(c *gin.Context) {
a2r.Call(auth.AuthClient.ParseToken, o.client, c)
2023-02-28 11:38:05 +08:00
}
2022-06-06 20:39:45 +08:00
2023-03-02 14:41:59 +08:00
func (o *Auth) ForceLogout(c *gin.Context) {
a2r.Call(auth.AuthClient.ForceLogout, o.client, c)
2022-06-06 20:39:45 +08:00
}