JWT Authentication endpoint

This commit is contained in:
Tim Beatham
2023-10-01 20:14:09 +01:00
parent 94afd68460
commit 52e5e3d33c
7 changed files with 175 additions and 30 deletions

View File

@ -6,6 +6,7 @@
package ctrlserver
import (
"context"
"errors"
"net"
"time"
@ -16,6 +17,7 @@ import (
"github.com/tim-beatham/wgmesh/pkg/wg"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"google.golang.org/grpc/metadata"
)
/*
@ -31,6 +33,7 @@ func NewCtrlServer(wgClient *wgctrl.Client, conn *conn.WgCtrlConnection, ifName
ctrlServer.Conn = conn
ctrlServer.IfName = ifName
ctrlServer.JwtManager = auth.NewJwtManager("bob123", 24*time.Hour)
ctrlServer.TokenManager = auth.NewTokenManager()
return ctrlServer
}
@ -192,3 +195,13 @@ func (s *MeshCtrlServer) EnableInterface(meshId string) error {
return wg.EnableInterface(s.IfName, node.WgHost)
}
func (s *MeshCtrlServer) AddToken(ctx context.Context, endpoint, meshId string) (context.Context, error) {
token, err := s.TokenManager.GetToken(meshId, endpoint)
if err != nil {
return nil, err
}
return metadata.AppendToOutgoingContext(ctx, "authorization", token), nil
}