From 6997becdd35df2580b75bd0fc3f00bb82817c678 Mon Sep 17 00:00:00 2001 From: hopleus Date: Thu, 31 Oct 2024 14:08:25 +0300 Subject: [PATCH] Fix OIDCCallbackHandler --- hscontrol/oidc.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hscontrol/oidc.go b/hscontrol/oidc.go index df182999..af03a16f 100644 --- a/hscontrol/oidc.go +++ b/hscontrol/oidc.go @@ -254,7 +254,8 @@ func (a *AuthProviderOIDC) OIDCCallbackHandler( // Register the node if it does not exist. if mKey != nil { - if err := a.registerNode(user, mKey, nodeExpiry); err != nil { + node, err = a.registerNode(user, mKey, nodeExpiry) + if err != nil { http.Error(writer, err.Error(), http.StatusInternalServerError) return } @@ -448,21 +449,22 @@ func (a *AuthProviderOIDC) registerNode( user *types.User, machineKey *key.MachinePublic, expiry time.Time, -) error { +) (*types.Node, error) { ipv4, ipv6, err := a.ipAlloc.Next() if err != nil { - return err + return nil, err } - if _, err := a.db.RegisterNodeFromAuthCallback( + node, err := a.db.RegisterNodeFromAuthCallback( *machineKey, types.UserID(user.ID), &expiry, util.RegisterMethodOIDC, ipv4, ipv6, - ); err != nil { - return fmt.Errorf("could not register node: %w", err) + ) + if err != nil { + return nil, fmt.Errorf("could not register node: %w", err) } - return nil + return node, nil }