auth

package
v0.0.0-...-8b501b0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flow

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

Flow implements the three-legged OAuth authentication flow.

func NewOAuthFlow

func NewOAuthFlow(cfg oauth2.Config, callbackListenAddr, redirectHost string) (*Flow, error)

NewOAuthFlow returns a Flow instance that can be used to execute a three-legged OAuth flow using the service provider from the specified configuration option. The callbackListenAddr specifies an address to bind to for handling OAuth redirect callbacks. If left empty, the default 127.0.0.1:8080 address will be used instead. The redirectHost parameter specifies the hostname to be inserted into generated redirect URLs. For CLI applications this can be left empty in which case the callback listen address will be used instead. For non-CLI services redirectHost would normally point to a load balancer instance that routes incoming requests to the specified callbackListenAddr.

func (*Flow) Authenticate

func (f *Flow) Authenticate() (string, <-chan Result, error)

Authenticate starts a new three-legged OAuth flow. It returns back a URL that the client must to visit to authorize access. Once the user has completed the manual authorization step, the authorization result will be published to the returned channel.

Clients can safely invoke Authenticate in a concurrent fashion.

func (*Flow) Close

func (f *Flow) Close() error

Close shuts down the HTTP server responsible for handling OAuth redirects and aborts any currently executing OAuth flows with an error.

type Result

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

Result represents the result of an OAuth authentication attempt.

func (*Result) Client

func (ar *Result) Client(ctx context.Context) (*http.Client, error)

Client returns an http.Client instance that automatically uses the OAuth token obtained from this authentication attempt when performing outgoing http requests. The returned client will also transparently refresh the token once it expires.

Jump to

Keyboard shortcuts

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