oauthtoken

package
v0.0.0-kmdagger1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ExpiryDelta is used to prevent any issue that is caused by the clock skew (server times can differ slightly between different machines).
	// Shouldn't be more than 30s
	ExpiryDelta            = 10 * time.Second
	ErrNoRefreshTokenFound = errors.New("no refresh token found")
	ErrNotAnOAuthProvider  = errors.New("not an oauth provider")
)

Functions

func IsOAuthPassThruEnabled

func IsOAuthPassThruEnabled(ds *datasources.DataSource) bool

IsOAuthPassThruEnabled returns true if Forward OAuth Identity (oauthPassThru) is enabled for the provided data source.

Types

type OAuthTokenService

type OAuthTokenService interface {
	GetCurrentOAuthToken(context.Context, *user.SignedInUser) *oauth2.Token
	IsOAuthPassThruEnabled(*datasources.DataSource) bool
	HasOAuthEntry(context.Context, *user.SignedInUser) (*login.UserAuth, bool, error)
	TryTokenRefresh(context.Context, *login.UserAuth) error
	InvalidateOAuthTokens(context.Context, *login.UserAuth) error
}

type Service

type Service struct {
	Cfg             *setting.Cfg
	SocialService   social.Service
	AuthInfoService login.AuthInfoService
	// contains filtered or unexported fields
}

func ProvideService

func ProvideService(socialService social.Service, authInfoService login.AuthInfoService, cfg *setting.Cfg) *Service

func (*Service) GetCurrentOAuthToken

func (o *Service) GetCurrentOAuthToken(ctx context.Context, usr *user.SignedInUser) *oauth2.Token

GetCurrentOAuthToken returns the OAuth token, if any, for the authenticated user. Will try to refresh the token if it has expired.

func (*Service) HasOAuthEntry

func (o *Service) HasOAuthEntry(ctx context.Context, usr *user.SignedInUser) (*login.UserAuth, bool, error)

HasOAuthEntry returns true and the UserAuth object when OAuth info exists for the specified User

func (*Service) InvalidateOAuthTokens

func (o *Service) InvalidateOAuthTokens(ctx context.Context, usr *login.UserAuth) error

InvalidateOAuthTokens invalidates the OAuth tokens (access_token, refresh_token) and sets the Expiry to default/zero

func (*Service) IsOAuthPassThruEnabled

func (o *Service) IsOAuthPassThruEnabled(ds *datasources.DataSource) bool

IsOAuthPassThruEnabled returns true if Forward OAuth Identity (oauthPassThru) is enabled for the provided data source.

func (*Service) TryTokenRefresh

func (o *Service) TryTokenRefresh(ctx context.Context, usr *login.UserAuth) error

TryTokenRefresh returns an error in case the OAuth token refresh was unsuccessful It uses a singleflight.Group to prevent getting the Refresh Token multiple times for a given User

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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