1
0
forked from extern/smegmesh
smegmesh/pkg/middleware/auth.go

33 lines
715 B
Go
Raw Normal View History

2023-10-01 20:01:35 +02:00
package middleware
import (
"context"
"errors"
"github.com/tim-beatham/wgmesh/pkg/auth"
logging "github.com/tim-beatham/wgmesh/pkg/log"
2023-10-01 20:01:35 +02:00
"github.com/tim-beatham/wgmesh/pkg/rpc"
)
type AuthRpcProvider struct {
rpc.UnimplementedAuthenticationServer
Manager *auth.JwtManager
2023-10-01 20:01:35 +02:00
}
func (a *AuthRpcProvider) JoinMesh(ctx context.Context, in *rpc.JoinAuthMeshRequest) (*rpc.JoinAuthMeshReply, error) {
meshId := in.MeshId
if meshId == "" {
return nil, errors.New("Must specify the meshId")
}
logging.InfoLog.Println("MeshID: " + in.MeshId)
token, err := a.Manager.CreateClaims(in.MeshId, in.Alias)
2023-10-01 20:01:35 +02:00
if err != nil {
return nil, err
}
return &rpc.JoinAuthMeshReply{Success: true, Token: token}, nil
}