auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REDIRECT_URI = "http://localhost:42069/callback"
	URI          = "http://localhost:42069"
	PORT         = "42069"
)

Variables

This section is empty.

Functions

func OpenURL

func OpenURL(url string) error

Types

type AccessToken

type AccessToken struct {
	Token  string    `json:"access_token"`
	Expiry time.Time `json:"time_created"`
}

func NewAccessToken

func NewAccessToken(str string) *AccessToken

func (*AccessToken) Load

func (t *AccessToken) Load(c *config.Config) error

Loads the access token from token file

func (*AccessToken) Refresh

func (t *AccessToken) Refresh(refreshToken *RefreshToken, c *config.Config) error

Refreshes the access token via valid refresh token. Then updates the token string and token file.

func (*AccessToken) String

func (t *AccessToken) String() string

Returns the token as a string

func (*AccessToken) Update

func (t *AccessToken) Update(tok string, c *config.Config) error

Update Updates the token value, and replaces the contents of the token file with the new token and an updated expiry time.

type RefreshToken

type RefreshToken struct {
	Token string `json:"refresh_token"`
}

func NewRefreshToken

func NewRefreshToken(tok string) *RefreshToken

func (*RefreshToken) Load

func (t *RefreshToken) Load(c *config.Config) error

Loads the token fields from the refresh token file.

func (*RefreshToken) String

func (t *RefreshToken) String() string

The token as a string

func (*RefreshToken) Update

func (t *RefreshToken) Update(tok string, c *config.Config) error

Updates the token file with new token.

type Session

type Session struct {
	AccessToken  *AccessToken
	RefreshToken *RefreshToken
}

func New

func New(c *config.Config) (*Session, error)

Creates a new session, loading tokens from respective files, and authenticating.

func (*Session) Authenticate

func (s *Session) Authenticate(c *config.Config) error

Authenticate is set to only run checks after the access token expiry period has elapsed. This is for faster runtime, should be perfectly okay unless token files are externally tappered. Checks if the access token is valid. If not, refreshes the access token. If the access token is not valid, reauthenticates s. Updating the token file.

Jump to

Keyboard shortcuts

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