auth

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const OIDC_TIMEOUT = 10 * time.Second

Variables

This section is empty.

Functions

func GetIDPSyncStatus

func GetIDPSyncStatus(ctx context.Context) models.IDPSyncStatus

func GetMatchingUser

func GetMatchingUser(ctx context.Context, oauthUser *OAuthUser) (*schema.User, error)

GetMatchingUser looks up an Azure AD user by UPN or external provider ID.

func HandleAuthCallback

func HandleAuthCallback(w http.ResponseWriter, r *http.Request)

HandleAuthCallback handles oauth callback. Note: not included in API reference as part of the OAuth process itself.

func HandleAuthLogin

func HandleAuthLogin(w http.ResponseWriter, r *http.Request)

swagger:route GET /api/oauth/login nodes HandleAuthLogin

Handles OAuth login.

		Schemes: https

		Security:
  		oauth
		Responses:
		200:  okResponse

func HandleHeadlessSSO

func HandleHeadlessSSO(w http.ResponseWriter, r *http.Request)

HandleHeadlessSSO handles the OAuth login flow for headless interfaces such as Netmaker CLI via websocket.

func HandleHeadlessSSOCallback

func HandleHeadlessSSOCallback(w http.ResponseWriter, r *http.Request)

HandleHeadlessSSOCallback - handle OAuth callback for headless logins such as Netmaker CLI

func HandleHostSSOCallback

func HandleHostSSOCallback(w http.ResponseWriter, r *http.Request)

HandleHostSSOCallback handles the callback from the sso endpoint It is the analogue of auth.handleNodeSSOCallback but takes care of the end point flow Retrieves the mkey from the state cache and adds the machine to the users email namespace TODO: A confirmation page for new machines should be added to avoid phishing vulnerabilities TODO: Add groups information from OIDC tokens into machine HostInfo Listens in /oidc/callback.

func IsOAuthConfigured

func IsOAuthConfigured(ctx context.Context) bool

IsOAuthConfigured reports whether an OAuth provider is configured for the scope in ctx.

func RegisterHostSSO

func RegisterHostSSO(w http.ResponseWriter, r *http.Request)

RegisterHostSSO redirects to the IDP for authentication Puts machine key in cache so the callback can retrieve it using the oidc state param Listens in /oidc/register/:regKey.

func ResetAuthProvider

func ResetAuthProvider(ctx context.Context)

ResetAuthProvider resets the auth provider for the scope in ctx.

func ResetIDPSyncHook

func ResetIDPSyncHook(ctx context.Context)

ResetIDPSyncHook re-reads the settings for the tenant carried in ctx and either (re)registers or stops that tenant's idp sync hook accordingly.

func StartIDPSyncHookForTenant added in v1.7.0

func StartIDPSyncHookForTenant(ctx context.Context)

func SyncFromIDP

func SyncFromIDP(ctx context.Context) error

func ValidateEmail added in v1.7.0

func ValidateEmail(w http.ResponseWriter, r *http.Request)

ValidateEmail - handles a user clicking the email-validation link sent to them on MSP deployments: marks their email validated and consumes the invite. @Summary Validate a user's email @Router /api/v1/users/validate-email [get] @Tags Users @Produce html @Param invite_code query string true "Validation invite code" @Param email query string true "User email"

Types

type AzureADProvider added in v1.7.0

type AzureADProvider struct {
	// contains filtered or unexported fields
}

AzureADProvider implements Provider for Azure Active Directory OAuth2.

func NewAzureADProvider added in v1.7.0

func NewAzureADProvider(redirectURL, clientID, clientSecret, azureTenantID string) *AzureADProvider

NewAzureADProvider constructs an AzureADProvider for the given OAuth2 credentials.

func (*AzureADProvider) Config added in v1.7.0

func (p *AzureADProvider) Config() *oauth2.Config

func (*AzureADProvider) GetUserInfo added in v1.7.0

func (p *AzureADProvider) GetUserInfo(state string, code string) (*OAuthUser, error)

func (*AzureADProvider) HandleCallback added in v1.7.0

func (p *AzureADProvider) HandleCallback(w http.ResponseWriter, r *http.Request)

func (*AzureADProvider) HandleLogin added in v1.7.0

func (p *AzureADProvider) HandleLogin(w http.ResponseWriter, r *http.Request)

func (*AzureADProvider) Name added in v1.7.0

func (p *AzureADProvider) Name() string

type GitHubProvider added in v1.7.0

type GitHubProvider struct {
	// contains filtered or unexported fields
}

GitHubProvider implements Provider for GitHub OAuth2.

func NewGitHubProvider added in v1.7.0

func NewGitHubProvider(redirectURL, clientID, clientSecret string) *GitHubProvider

NewGitHubProvider constructs a GitHubProvider for the given OAuth2 credentials.

func (*GitHubProvider) Config added in v1.7.0

func (p *GitHubProvider) Config() *oauth2.Config

func (*GitHubProvider) GetUserInfo added in v1.7.0

func (p *GitHubProvider) GetUserInfo(state, code string) (*OAuthUser, error)

func (*GitHubProvider) HandleCallback added in v1.7.0

func (p *GitHubProvider) HandleCallback(w http.ResponseWriter, r *http.Request)

func (*GitHubProvider) HandleLogin added in v1.7.0

func (p *GitHubProvider) HandleLogin(w http.ResponseWriter, r *http.Request)

func (*GitHubProvider) Name added in v1.7.0

func (p *GitHubProvider) Name() string

type GoogleProvider added in v1.7.0

type GoogleProvider struct {
	// contains filtered or unexported fields
}

GoogleProvider implements Provider for Google OAuth2.

func NewGoogleProvider added in v1.7.0

func NewGoogleProvider(redirectURL, clientID, clientSecret string) *GoogleProvider

NewGoogleProvider constructs a GoogleProvider for the given OAuth2 credentials.

func (*GoogleProvider) Config added in v1.7.0

func (p *GoogleProvider) Config() *oauth2.Config

func (*GoogleProvider) GetUserInfo added in v1.7.0

func (p *GoogleProvider) GetUserInfo(state string, code string) (*OAuthUser, error)

func (*GoogleProvider) HandleCallback added in v1.7.0

func (p *GoogleProvider) HandleCallback(w http.ResponseWriter, r *http.Request)

func (*GoogleProvider) HandleLogin added in v1.7.0

func (p *GoogleProvider) HandleLogin(w http.ResponseWriter, r *http.Request)

func (*GoogleProvider) Name added in v1.7.0

func (p *GoogleProvider) Name() string

type OAuthUser

type OAuthUser struct {
	ID                StringOrInt `json:"id" bson:"id"`
	Name              string      `json:"name" bson:"name"`
	Email             string      `json:"email" bson:"email"`
	Login             string      `json:"login" bson:"login"`
	UserPrincipalName string      `json:"userPrincipalName" bson:"userPrincipalName"`
	AccessToken       string      `json:"accesstoken" bson:"accesstoken"`
}

OAuthUser - generic OAuth strategy user

type OIDCProvider added in v1.7.0

type OIDCProvider struct {
	// contains filtered or unexported fields
}

OIDCProvider implements Provider for OIDC-compatible identity providers (including Okta).

func NewOIDCProvider added in v1.7.0

func NewOIDCProvider(redirectURL, clientID, clientSecret, issuer string) (*OIDCProvider, error)

NewOIDCProvider constructs an OIDCProvider by performing OIDC discovery against the issuer URL.

func NewOktaProvider added in v1.7.0

func NewOktaProvider(redirectURL, clientID, clientSecret, issuer string) (*OIDCProvider, error)

NewOktaProvider constructs an OIDCProvider configured for Okta. Okta uses standard OIDC discovery; this is a thin alias over NewOIDCProvider.

func (*OIDCProvider) Config added in v1.7.0

func (p *OIDCProvider) Config() *oauth2.Config

func (*OIDCProvider) GetUserInfo added in v1.7.0

func (p *OIDCProvider) GetUserInfo(state string, code string) (u *OAuthUser, e error)

func (*OIDCProvider) HandleCallback added in v1.7.0

func (p *OIDCProvider) HandleCallback(w http.ResponseWriter, r *http.Request)

func (*OIDCProvider) HandleLogin added in v1.7.0

func (p *OIDCProvider) HandleLogin(w http.ResponseWriter, r *http.Request)

func (*OIDCProvider) Name added in v1.7.0

func (p *OIDCProvider) Name() string

type Provider added in v1.7.0

type Provider interface {
	Name() string
	Config() *oauth2.Config
	HandleLogin(http.ResponseWriter, *http.Request)
	HandleCallback(http.ResponseWriter, *http.Request)
	GetUserInfo(state, code string) (*OAuthUser, error)
}

Provider is implemented by each OAuth provider.

type ProviderRegistry added in v1.7.0

type ProviderRegistry struct {
	// contains filtered or unexported fields
}

func Registry added in v1.7.0

func Registry() *ProviderRegistry

func (*ProviderRegistry) Delete added in v1.7.0

func (p *ProviderRegistry) Delete(scopeLevel scope.Scope, scopeID string)

func (*ProviderRegistry) FromContext added in v1.7.0

func (p *ProviderRegistry) FromContext(ctx context.Context) (Provider, bool)

FromContext returns the provider for the scope embedded in ctx.

type StringOrInt

type StringOrInt string

func (*StringOrInt) UnmarshalJSON

func (s *StringOrInt) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL