initial work on OIDC (SSO) integration

This commit is contained in:
Raal Goff 2021-09-26 16:53:05 +08:00
parent 83815f567d
commit e7a2501fe8
6 changed files with 347 additions and 4 deletions

17
api.go
View file

@ -133,8 +133,13 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
Str("handler", "Registration").
Str("machine", m.Name).
Msg("Not registered and not NodeKey rotation. Sending a authurl to register")
resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
h.cfg.ServerURL, mKey.HexString())
if h.cfg.OIDCEndpoint != "" {
resp.AuthURL = fmt.Sprintf("%s/oidc/register/%s", h.cfg.ServerURL, mKey.HexString())
} else {
resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
h.cfg.ServerURL, mKey.HexString())
}
respBody, err := encode(resp, &mKey, h.privateKey)
if err != nil {
log.Error().
@ -199,8 +204,12 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
Str("handler", "Registration").
Str("machine", m.Name).
Msg("The node is sending us a new NodeKey, sending auth url")
resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
h.cfg.ServerURL, mKey.HexString())
if h.cfg.OIDCEndpoint != "" {
resp.AuthURL = fmt.Sprintf("%s/oidc/register/%s", h.cfg.ServerURL, mKey.HexString())
} else {
resp.AuthURL = fmt.Sprintf("%s/register?key=%s",
h.cfg.ServerURL, mKey.HexString())
}
respBody, err := encode(resp, &mKey, h.privateKey)
if err != nil {
log.Error().