Fix OIDCCallbackHandler

This commit is contained in:
hopleus 2024-10-31 14:08:25 +03:00
parent 38533c99aa
commit 6997becdd3

View file

@ -254,7 +254,8 @@ func (a *AuthProviderOIDC) OIDCCallbackHandler(
// Register the node if it does not exist. // Register the node if it does not exist.
if mKey != nil { 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) http.Error(writer, err.Error(), http.StatusInternalServerError)
return return
} }
@ -448,21 +449,22 @@ func (a *AuthProviderOIDC) registerNode(
user *types.User, user *types.User,
machineKey *key.MachinePublic, machineKey *key.MachinePublic,
expiry time.Time, expiry time.Time,
) error { ) (*types.Node, error) {
ipv4, ipv6, err := a.ipAlloc.Next() ipv4, ipv6, err := a.ipAlloc.Next()
if err != nil { if err != nil {
return err return nil, err
} }
if _, err := a.db.RegisterNodeFromAuthCallback( node, err := a.db.RegisterNodeFromAuthCallback(
*machineKey, *machineKey,
types.UserID(user.ID), types.UserID(user.ID),
&expiry, &expiry,
util.RegisterMethodOIDC, util.RegisterMethodOIDC,
ipv4, ipv6, 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
} }