oauther

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultStorePrefix is the prefix used when storing information in the KVStore by default.
	DefaultStorePrefix = "oauth_"
	// DefaultOAuthURL is the URL the OAuther will use to register its endpoints by default.
	DefaultOAuthURL = "/oauth2"
	// DefaultConnectedString is the string shown to the user when the oauth flow is completed by default.
	DefaultConnectedString = "Successfully connected. Please close this window."
	// DefaultOAuth2StateTimeToLive is the duration the states from the OAuth flow will live in the KVStore by default.
	DefaultOAuth2StateTimeToLive = 5 * time.Minute
	// DefaultPayloadTimeToLive is the duration the user payload will live in the KVStore by default.
	DefaultPayloadTimeToLive = 10 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OAuther

type OAuther interface {
	// GetToken returns the oauth token for userID, or error if it does not exist or there is any store error.
	GetToken(userID string) (*oauth2.Token, error)
	// GetConnectURL returns the URL to reach in order to start the OAuth flow.
	GetConnectURL() string
	// Deauthorize removes the token for userID. Return error if there is any store error.
	Deauthorize(userID string) error
	// ServeHTTP implements http.Handler
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	// AddPayload stores some information to be returned after the flow is over
	AddPayload(userID string, payload []byte) error
}

OAuther defines an object able to perform the OAuth flow.

func New

func New(
	pluginURL string,
	oAuthConfig oauth2.Config,
	onConnect func(userID string, token oauth2.Token, payload []byte),
	store common.KVStore,
	l logger.Logger,
	options ...Option,
) OAuther

New creates a new OAuther.

- pluginURL: The base URL for the plugin (e.g. https://www.instance.com/plugins/pluginid).

- oAuthConfig: The configuration of the Authorization flow to perform.

- onConnect: What to do when the Authorization process is complete.

- store: A KVStore to store the data of the OAuther.

- l Logger: A logger to log errors during authorization.

- options: Optional options for the OAuther. Available options are StorePrefix, OAuthURL, ConnectedString and OAuth2StateTimeToLive.

func NewFromClient

func NewFromClient(
	client *pluginapi.Client,
	oAuthConfig oauth2.Config,
	onConnect func(userID string, token oauth2.Token, payload []byte),
	l logger.Logger,
	options ...Option,
) OAuther

NewFromClient creates a new OAuther from the plugin api client.

- pluginapi: A plugin api client.

- pluginID: The plugin ID.

- oAuthConfig: The configuration of the Authorization flow to perform.

- onConnect: What to do when the Authorization process is complete.

- l Logger: A logger to log errors during authorization.

- options: Optional options for the OAuther. Available options are StorePrefix, OAuthURL, ConnectedString and OAuth2StateTimeToLive.

type Option

type Option func(*oAuther)

Option defines each option that can be passed in the creation of the OAuther. Options functions available are OAuthURL, StorePrefix, ConnectedString and OAuth2StateTimeToLive and PayloadTimeToLive.

func ConnectedString

func ConnectedString(text string) Option

ConnectedString defines the string shown to the user when the oauth flow is completed. Defaults to "Successfully connected. Please close this window.".

func OAuth2StateTimeToLive

func OAuth2StateTimeToLive(ttl time.Duration) Option

OAuth2StateTimeToLive is the duration the states from the OAuth flow will live in the KVStore. Defaults to 5 minutes.

func OAuthURL

func OAuthURL(url string) Option

OAuthURL defines the URL the OAuther will use to register its endpoints. Defaults to "/oauth2".

func PayloadTimeToLive

func PayloadTimeToLive(ttl time.Duration) Option

PayloadTimeToLive is the duration the payload from the OAuth flow will live in the KVStore. Defaults to 10 minutes.

func StorePrefix

func StorePrefix(prefix string) Option

StorePrefix defines the prefix the OAuther will use to store information in the KVStore. Defaults to "oauth_".

Directories

Path Synopsis
Package mock_oauther is a generated GoMock package.
Package mock_oauther is a generated GoMock package.
Package mock_oauther is a generated GoMock package.
Package mock_oauther is a generated GoMock package.

Jump to

Keyboard shortcuts

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