utils

package
v0.0.0-...-d1f6640 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidProviders = map[string]bool{
	"google":  true,
	"outlook": true,
}

ValidProviders is a slice of valid OAuth2 providers

Functions

func ExchangeCodeForToken

func ExchangeCodeForToken(config *oauth2.Config, authCode string) (*oauth2.Token, error)

ExchangeCodeForToken handles the redirect from the OAuth2 provider and exchanges the code for a token

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists and is not a directory before we

func GenerateAPIKey

func GenerateAPIKey() (string, error)

GenerateAPIKey generates an 32 byte API key in Hex format

func GenerateOauthURL

func GenerateOauthURL(config *oauth2.Config, provider string, flowType string) (string, string, error)

GenerateOauthURL prints the URL to visit to authorize the application

func GetOAuth2Config

func GetOAuth2Config(provider string) (*oauth2.Config, error)

GetOAuth2Config returns the OAuth2 config for the specified provider

func GetTokenFromRefreshToken

func GetTokenFromRefreshToken(config *oauth2.Config, refreshToken string) (*oauth2.Token, error)

GetTokenFromRefreshToken retrieves a token from a refresh token

func PollToken

func PollToken(config *oauth2.Config, deviceCode string) (*oauth2.Token, error)

PollToken Poll Google's authorization server to retrieve the token

func RetrieveToken

func RetrieveToken(provider string) (*oauth2.Token, error)

RetrieveToken retrieves the OAuth token from redis.

func SaveToken

func SaveToken(provider string, token *oauth2.Token) error

SaveToken saves the token to redis.

func UpdateToken

func UpdateToken(provider string, token *oauth2.Token) error

UpdateToken updates the token in redis.

Types

type OAuth2Config

type OAuth2Config struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	RedirectURL  string   `json:"redirect_url"`
	Scopes       []string `json:"scopes"`
	AuthURL      string   `json:"auth_url"`
	TokenURL     string   `json:"token_url"`
}

OAuth2Config is a struct to hold the OAuth2 configuration

Jump to

Keyboard shortcuts

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