You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/api/auth.go

52 lines
1.3 KiB

2 years ago
package api
3 years ago
import (
"context"
2 years ago
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
1 year ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
"github.com/gin-gonic/gin"
1 year ago
"google.golang.org/grpc"
3 years ago
)
2 years ago
func NewAuth(c discoveryregistry.SvcDiscoveryRegistry) *Auth {
1 year ago
conn, err := c.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName)
if err != nil {
panic(err)
}
1 year ago
log.ZInfo(context.Background(), "auth rpc conn", "conn", conn)
1 year ago
return &Auth{conn: conn, discov: c}
3 years ago
}
2 years ago
type Auth struct {
1 year ago
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
2 years ago
}
3 years ago
2 years ago
func (o *Auth) client(ctx context.Context) (auth.AuthClient, error) {
1 year ago
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImAuthName)
if err != nil {
return nil, err
}
return auth.NewAuthClient(c), nil
3 years ago
}
3 years ago
2 years ago
func (o *Auth) UserRegister(c *gin.Context) {
2 years ago
//a2r.Call(auth.AuthClient.UserRegister, o.client, c) // todo
3 years ago
}
2 years ago
2 years ago
func (o *Auth) UserToken(c *gin.Context) {
a2r.Call(auth.AuthClient.UserToken, o.client, c)
2 years ago
}
2 years ago
2 years ago
func (o *Auth) ParseToken(c *gin.Context) {
a2r.Call(auth.AuthClient.ParseToken, o.client, c)
2 years ago
}
2 years ago
2 years ago
func (o *Auth) ForceLogout(c *gin.Context) {
a2r.Call(auth.AuthClient.ForceLogout, o.client, c)
2 years ago
}