mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
Drop the Avalanche-heritage /ext prefix; /v1 is the single canonical route surface (one way, no backward compat). The node's baseURL is the source of truth; clients, SDKs, CLI, indexer, maker, genesis, netrunner, and the k8s/compose/gateway/explorer configs are updated to match. Co-authored-by: Hanzo Dev <dev@hanzo.ai>
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/luxfi/log"
|
|
apitypes "github.com/luxfi/api/types"
|
|
)
|
|
|
|
// Service that serves the Auth API functionality.
|
|
type Service struct {
|
|
auth *auth
|
|
}
|
|
|
|
type Password struct {
|
|
Password string `json:"password"` // The authorization password
|
|
}
|
|
|
|
type NewTokenArgs struct {
|
|
Password
|
|
// Endpoints that may be accessed with this token e.g. if endpoints is
|
|
// ["/v1/bc/X", "/v1/admin"] then the token holder can hit the X-Chain API
|
|
// and the admin API. If [Endpoints] contains an element "*" then the token
|
|
// allows access to all API endpoints. [Endpoints] must have between 1 and
|
|
// [maxEndpoints] elements
|
|
Endpoints []string `json:"endpoints"`
|
|
}
|
|
|
|
type Token struct {
|
|
Token string `json:"token"` // The new token. Expires in [TokenLifespan].
|
|
}
|
|
|
|
func (s *Service) NewToken(_ *http.Request, args *NewTokenArgs, reply *Token) error {
|
|
s.auth.log.Debug("API called",
|
|
log.String("service", "auth"),
|
|
log.String("method", "newToken"),
|
|
)
|
|
|
|
var err error
|
|
reply.Token, err = s.auth.NewToken(args.Password.Password, defaultTokenLifespan, args.Endpoints)
|
|
return err
|
|
}
|
|
|
|
type RevokeTokenArgs struct {
|
|
Password
|
|
Token
|
|
}
|
|
|
|
func (s *Service) RevokeToken(_ *http.Request, args *RevokeTokenArgs, _ *apitypes.EmptyReply) error {
|
|
s.auth.log.Debug("API called",
|
|
log.String("service", "auth"),
|
|
log.String("method", "revokeToken"),
|
|
)
|
|
|
|
return s.auth.RevokeToken(args.Token.Token, args.Password.Password)
|
|
}
|
|
|
|
type ChangePasswordArgs struct {
|
|
OldPassword string `json:"oldPassword"` // Current authorization password
|
|
NewPassword string `json:"newPassword"` // New authorization password
|
|
}
|
|
|
|
func (s *Service) ChangePassword(_ *http.Request, args *ChangePasswordArgs, _ *apitypes.EmptyReply) error {
|
|
s.auth.log.Debug("API called",
|
|
log.String("service", "auth"),
|
|
log.String("method", "changePassword"),
|
|
)
|
|
|
|
return s.auth.ChangePassword(args.OldPassword, args.NewPassword)
|
|
}
|