browser

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package browser provides an interactive Safeguard login that opens the user's system web browser to complete OAuth authorization (the authorization-code flow with PKCE). It is an optional add-on: importing it pulls in the machinery to launch a browser and run a loopback HTTP listener, so headless and server consumers that never need an interactive login are not forced to compile it in.

The resulting session is not refreshable, matching SafeguardDotNet and PySafeguard, which treat browser logins as existing-token connections. To obtain a new token, call Connect again.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAuthorizationCode = errors.New("browser: redirect carried no authorization code")

ErrNoAuthorizationCode indicates the loopback listener received the browser redirect but it carried no authorization code. Compare with errors.Is.

Functions

func Connect

func Connect(ctx context.Context, host string, opts ...Option) (*safeguard.Client, error)

Connect authenticates to the Safeguard appliance at host by opening the system browser for OAuth authorization and returns a ready client. It runs a loopback HTTP listener on 127.0.0.1 to capture the authorization code the appliance redirects back, exchanges it for a Safeguard user token, and hands that token to the SDK. The call blocks until the user completes authentication, the context is canceled, or an error occurs.

Types

type Option

type Option func(*config)

Option configures a browser login.

func WithBrowserOpener

func WithBrowserOpener(open func(url string) error) Option

WithBrowserOpener overrides how the authorization URL is opened. The default launches the operating system's default browser. Supply a custom opener to integrate with an embedded browser, to log the URL for a remote user, or to drive tests.

func WithConnectionOptions

func WithConnectionOptions(opts ...safeguard.Option) Option

WithConnectionOptions forwards standard connection options (TLS trust, API version, timeouts, logger) to the underlying safeguard.Connect call.

func WithLoginHint

func WithLoginHint(username string) Option

WithLoginHint pre-fills the appliance login form with username by passing it as the OAuth login_hint. It is a convenience only; the user still authenticates in the browser.

func WithPort

func WithPort(port int) Option

WithPort binds the loopback redirect listener to a fixed TCP port on 127.0.0.1. The default is 0, which lets the operating system choose a free ephemeral port; the chosen port is passed to the appliance in the redirect URI. Set a fixed port only when a firewall or the appliance requires one.

Jump to

Keyboard shortcuts

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