Documentation
¶
Overview ¶
auth is a package containing an authentication client built around Firebase REST API.
See https://firebase.google.com/docs/reference/rest for more information.
fields is a package containing structures for storing user prompted data such as email or password.
forms is package contaning structures to work with user input during Firebase authentication process.
Authentication related utilities around firebase REST authentication workflow. See https://firebase.google.com/docs/reference/rest for more information.
Index ¶
- Constants
- Variables
- func BillingFeatureExpired(billingFeature forestvpn_api.BillingFeature) bool
- func BillingFeautureExists(userID string) bool
- func Date2Json(date time.Time) ([]byte, error)
- func DumpAccessTokenExpireDate(userID string, expires_in string) error
- func GetAccessTokenExpireDate(expireTime string) (time.Time, error)
- func HandleFirebaseAuthResponse(response *resty.Response) (string, error)
- func HandleFirebaseSignInResponse(response *resty.Response) error
- func HandleFirebaseSignUpResponse(response *resty.Response) error
- func Init() error
- func IsAccessTokenExpired(userID string) (bool, error)
- func IsActiveProfile(userID string) bool
- func IsAuthenticated() bool
- func IsRefreshTokenExists() (bool, error)
- func JsonDump(data []byte, filepath string) error
- func LoadAccessToken(userID string) (string, error)
- func LoadAccessTokenExpireDate(userID string) (time.Time, error)
- func LoadBillingFeatures(userID string) ([]forestvpn_api.BillingFeature, error)
- func LoadDevice(userID string) (*forestvpn_api.Device, error)
- func LoadFirebaseAuthFile(userID string) (map[string]any, error)
- func LoadFirebaseExtensionFile(userID string) (map[string]string, error)
- func LoadIdToken(userID string) (string, error)
- func LoadRefreshToken() (string, error)
- func LoadUserID() (string, error)
- func RemoveActiveUserLockFile() error
- func RemoveFirebaseAuthFile(userID string) error
- func SetActiveProfile(userID string) error
- func UpdateProfileDevice(device *forestvpn_api.Device) error
- type AccountsMap
- type AuthClient
- type EmailField
- type Info
- type InfoForm
- type PasswordConfirmationField
- type PasswordField
- type SignInForm
- type SignUpForm
Constants ¶
const AccountsMapFile = ".accounts.json"
AccountsMapFile is a file to dump the AccountsMap structure that holds the mappings from user logged in emails to uuids.
const ActiveUserLockFile string = "/.active.lock"
const BillingFeatureFile = "/billing.json"
BillingFeatureFile is a file to store user's billing features locally.
const DeviceFile string = "/device.json"
The DeviceFile represents the device created for the user.
Read more: https://github.com/forestvpn/api-client-go.
const FirebaseAuthFile = "/firebase.json"
FirebaseAuthFile is a file to dump Firebase responses.
const FirebaseExtensionFile = "/firebase-ext.json"
FirebaseExtensionFile contains access token expiration date recieved from firebase login response's expire time value.
const WireguardConfig = "/fvpn0.conf"
WireguardConfig is a Wireguard configuration file.
It's being rewrittten per location change.
Variables ¶
var AppDir = home + "/.forestvpn/"
AppDir is Forest CLI application directory.
var ProfilesDir = AppDir + "profiles/"
var SessionFile = AppDir + "session.json"
Deprecated: The SessionFile is a file for storing the last session information.
It's used to track down the status of connection.
Functions ¶
func BillingFeatureExpired ¶
func BillingFeatureExpired(billingFeature forestvpn_api.BillingFeature) bool
BillingFeatureExpired is a function to check whether the expire date of given billing feature is before current local time.
func BillingFeautureExists ¶
BillingFeautureExists is a helper function to quickly check whether the local billing features exists for the user with id value of given user id.
func DumpAccessTokenExpireDate ¶
DumpAccessTokenExpireDate is a function to write access token exparation date into the FirebaseExtensionFile for the user with id value of given user id.
func GetAccessTokenExpireDate ¶
GetAccessTokenExpireDate is a function to create a time.Time object from numeric string value. The numeric string values is a value that comes from the firebase login response and indicates the duration of an access token exparation period in seconds. The numeric string value is added to the current local time right after the firebase login response. Thus, GetAccessTokenExpireDate returns the time object with exparation date of an access token.
func HandleFirebaseAuthResponse ¶
HandleFirebaseAuthResponse is a function to extracts the error message from the Firebase REST API response when the status is ok.
func HandleFirebaseSignInResponse ¶
HandleFirebaseSignInResponse is a function that dumps the Firebase REST API response into FirebaseAuthFile.
func HandleFirebaseSignUpResponse ¶
HandleFirebaseSignUpResponse is a function to check whether there's an error in firebase response from it's sign up endpoint.
See https://firebase.google.com/docs/reference/rest/auth#section-create-email-password for more information.
func IsAccessTokenExpired ¶
IsAccessTokenExpired is a function that reads an access token exparation date of the user with id value of given user id from the local firebase sign in response.
func IsActiveProfile ¶
IsActiveProfile is a function to check if the given user ID is an ID of currently active (logged in) user.
func IsAuthenticated ¶
func IsAuthenticated() bool
IsAuthenticated is a helper function to quickly check wether user is authenticated by checking existance of an access token.
func IsRefreshTokenExists ¶
IsRefreshTokenExists is a function to quickly check refresh token exists locally.
func LoadAccessToken ¶
LoadAccessToken is a helper function to quickly read and return access token of specific user by user ID from the firebase login response avalable locally.
func LoadAccessTokenExpireDate ¶
LoadAccessTokenExpireDate is a function to load the exparation date of an access token for user with id value of given user id.
func LoadBillingFeatures ¶
func LoadBillingFeatures(userID string) ([]forestvpn_api.BillingFeature, error)
LoadBillingFeatures is a function to read local billing features from file for the user with id value of given user id.
func LoadDevice ¶
func LoadDevice(userID string) (*forestvpn_api.Device, error)
LoadDevice is a function that reads local device file depending on the user ID provided and returns it as a forestvpn_api.Device.
func LoadFirebaseAuthFile ¶
LoadFirebaseAuthFile is a function to get local firebase authentication response per user by the user ID.
func LoadFirebaseExtensionFile ¶
LoadFirebaseExtensionFile is a function to read FirebaseExtensionFile and return an access token expire date it contains for the user with id value of given user id.
func LoadIdToken ¶
LoadIdToken is a function to load id token of the user with id value of given user id from the local firebase login response.
func LoadRefreshToken ¶
LoadRefreshToken is a function to quickly get the local refresh token from FirebaseAuthFile.
func LoadUserID ¶
LoadUserID is a helper function to quickly read and return user ID of currently active user from the firebase login response avalable locally.
func RemoveActiveUserLockFile ¶
func RemoveActiveUserLockFile() error
RemoveActiveUserLockFile is a helper function to quickly diactivate currently active (logged in) user.
func RemoveFirebaseAuthFile ¶
RemoveFirebaseAuthFile is a function to remove FirebaseAuthFile of the user with given user ID. Used to log out the user.
func SetActiveProfile ¶
SetActiveProfile is a function to set the user profile with given user ID active. To set the profile active: 1. Find another active profile if exists 2. Diactivate currently active profile if found on step 1. 3. Activate profile with id of given userID
How the profiles are activated or diactivated.
Each user profile isolated in the own profile directory named by user's uuid. When profile X is activated: 1. The lock file is removed from other profiles directories if found. 2. The lock file is created in the directory of X profile.
ActiveUserLockFile - is a lock file. It's an empty file that only serves to indicate whether profile is active. When profile X is diactivated, the lock file is removed from the X profile directory.
func UpdateProfileDevice ¶
func UpdateProfileDevice(device *forestvpn_api.Device) error
UpdateProfileDevice is a helper function to quickly update the local device file of the logged in (active) user.
Types ¶
type AccountsMap ¶
type AccountsMap struct {
// contains filtered or unexported fields
}
AccountsMap is a structure that helps to track down user's logins and logouts. It also helps to show local accounts in account ls command.
func GetAccountsMap ¶
func GetAccountsMap(accountsMapFile string) AccountsMap
GetAccountMap is a faactory function to get the AccountsMap structure
func (AccountsMap) AddAccount ¶
func (a AccountsMap) AddAccount(email string, userID string) error
AddAccount is a method to add a new logged in account to the AccountMap.
func (AccountsMap) GetEmail ¶
func (a AccountsMap) GetEmail(userID string) string
func (AccountsMap) GetUserID ¶
func (a AccountsMap) GetUserID(email string) string
GetUserID is a method to get uuid of a user by related email.
func (AccountsMap) ListLocalAccounts ¶
func (a AccountsMap) ListLocalAccounts() error
ListLocalAccounts is a method to print local user accounts in a table.
func (AccountsMap) RemoveAccount ¶
func (a AccountsMap) RemoveAccount(userID string) error
RemoveAccount is a method to remove knonw local account from AccountMap. It loads AccountMap structure from the AccountMapFile, removes the key with value of userID and dumps updated data using JsonDump.
type AuthClient ¶
type AuthClient struct {
ApiKey string
}
AuthClient is a structure used as a Firebase REST client.
See https://firebase.google.com/docs/reference/rest for more information.
func (AuthClient) GetAccessToken ¶
func (c AuthClient) GetAccessToken(refreshToken string) (*resty.Response, error)
GetAccessToken is a method to obtain a new access token from Firebase REST API and dump the response into FirebaseAuthFile.
func (AuthClient) GetUserData ¶
func (c AuthClient) GetUserData(idToken string) (*resty.Response, error)
GetUserData is used to check if the user already exists in the Firebase database during the registration.
See https://firebase.google.com/docs/reference/rest/auth#section-get-account-info for more information.
func (AuthClient) SignIn ¶
func (c AuthClient) SignIn(form SignInForm) (*resty.Response, error)
SignIn is a method to perform a Firebase sign in request. It accepts an instance of a SignInForm that holds validated data for request.
See https://firebase.google.com/docs/reference/rest/auth#section-sign-in-email-password for more information.
func (AuthClient) SignUp ¶
func (c AuthClient) SignUp(form SignUpForm) (*resty.Response, error)
SignUp is a method to perform a Firebase sign up request. It accepts an instance of a SignUpForm that holds validated data for request.
See https://firebase.google.com/docs/reference/rest/auth#section-create-email-password for more information.
type EmailField ¶
type EmailField struct {
Value string
}
EmailField is a structure that holds an email value that could be validated.
func GetEmailField ¶
func GetEmailField(email string) (EmailField, error)
GetEmailField is a method that prompts a user an email and then validates it.
func (EmailField) Validate ¶
func (f EmailField) Validate() error
Validate is a method to check user's email address.
type PasswordConfirmationField ¶
type PasswordConfirmationField struct {
Value []byte
}
PasswordConfirmationField is used in the SignUpForm to store the confirmation of a password.
type PasswordField ¶
type PasswordField struct {
Value []byte
}
PasswordField is a structure that holds a password value that could be validated.
func GetPasswordField ¶
func GetPasswordField(password []byte, validate bool) (PasswordField, error)
getPasswordField is a method that prompts the user a password and then validates it. validate is a boolean that allows to enable or disable password validation. E.g. when password validation is needed on registration but not on login.
func (PasswordField) Validate ¶
func (p PasswordField) Validate() error
Validate is a method to check password's strength.
type SignInForm ¶
type SignInForm struct {
EmailField
PasswordField
}
SignInForm is a structure to store user's email and password.
type SignUpForm ¶
type SignUpForm struct {
SignInForm
PasswordConfirmationField
}
SignUpForm is a structure that holds the SignInForm and the password confirmation.
func (SignUpForm) ValidatePasswordConfirmation ¶
func (s SignUpForm) ValidatePasswordConfirmation() error
ValidatePasswordConfirmation is a method that compares password and the password confirmation values.