2023-10-01 20:01:35 +02:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
"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
|
2023-10-02 17:03:41 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2023-10-02 17:03:41 +02:00
|
|
|
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
|
|
|
|
}
|