Command line tool for OpenIM
go install github.com/honlyc/openim-cmdline/openim
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install github.com/honlyc/openim-cmdline/protoc-gen-go-http
docs: https://grpc.io/docs/protoc-installation/
Mac:
brew install protobuf
auth.proto
syntax = "proto3";
package OpenIMCmdLine.auth;
option go_package = "github.com/honlyc/openim-cmdline/protocol/auth";
import "google/api/annotations.proto";
import "options/openim.proto";
message userTokenReq {
string secret = 1;
int32 platformID = 2;
string userID = 3;
}
message userTokenResp {
string token = 2;
int64 expireTimeSeconds = 3;
}
message getUserTokenReq{
int32 platformID = 1;
string userID = 2;
}
message getUserTokenResp{
string token = 1;
int64 expireTimeSeconds = 2;
}
service Auth {
// 路由内校验 token
option (openim.server).token = true;
//生成token
rpc userToken(userTokenReq) returns(userTokenResp){
option (google.api.http) = {
post: "/auth/user_token",
body: "*"
};
};
// 管理员获取用户 token
rpc getUserToken(getUserTokenReq)returns(getUserTokenResp){
option (google.api.http) = {
post: "/auth/get_user_token",
body: "*"
};
// path 内校验 Token
option (openim.method).token = true;
};
}
openim proto client auth/auth.proto -- --proto_path=/usr/local/include/
r := gin.New()
// get Token Parser by Gin HandlerFunc
ParseToken := GinParseToken(config)
authApi := NewAuthApi(*authRpc)
auth.RegisterAuthHTTPServer(r, ParseToken, &authApi)
a := NewAuthApi(*authRpc)
// Before ⬇️
authRouterGroup := r.Group("/auth")
{
authRouterGroup.POST("/user_token", a.UserToken)
authRouterGroup.POST("/get_user_token", ParseToken, a.GetUserToken)
authRouterGroup.POST("/parse_token", a.ParseToken)
authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout)
}
// After ⬇️
auth.RegisterAuthHTTPServer(r, ParseToken, &a)