auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const RedactedToken = "--REDACTED--"

RedactedToken is the value returned by calling String() on a Token.

Variables

View Source
var (
	ErrInvalidURL = fmt.Errorf("must provide valid tavern url")
)

ErrInvalidURL occurs if an invalid Tavern url is provided.

Functions

This section is empty.

Types

type Browser

type Browser interface {
	OpenURL(url string) error
}

Browser that will be opened to the Tavern authentication flow.

type BrowserFunc

type BrowserFunc func(tavernURL string) error

The BrowserFunc type is an adapter to allow the use of ordinary functions as browsers. If f is a function with the appropriate signature, then BrowserFunc(f) is a Browser that calls f.

func (BrowserFunc) OpenURL

func (f BrowserFunc) OpenURL(tavernURL string) error

OpenURL calls f(tavernURL).

type Token

type Token string

Token is a type alias for string that prevents sensitive information from being displayed.

func Authenticate

func Authenticate(ctx context.Context, browser Browser, tavernURL string) (Token, error)

Authenticate the user to the Tavern API using the provided browser. This will open the browser to a login URL, which will redirect to an http server (hosted locally) with authentication credentials. This prevents the need for copy pasting tokens manually.

After authenticating, the resulting Token may be used to authenticate to Tavern for HTTP requests. This should be done by calling the `Authenticate(request)` method on the returned token.

func (Token) Authenticate

func (token Token) Authenticate(r *http.Request)

Authenticate the provided http request, using this token to authenticate to the Tavern API. It is recommended to use this method instead of manually configuring the request, such that if authentication implementation details are changed, the request will still be properly authenticated.

func (Token) String

func (Token) String() string

String returns the RedactedToken message to avoid accidentally printing sensitive information. In order to display the token intentionally, you must explicitly cast it to a string before printing.

Jump to

Keyboard shortcuts

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