firefox_container

package module
v0.0.0-...-691fa73 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 17 Imported by: 0

README

firefox_container

A driver for automated authentications using Firefox Portable.

Installation

In your Go project, run

go get -u github.com/enzo-santos/firefox_container

and use it in your code:

package main

import (
	"github.com/enzo-santos/firefox_container"
)

func main() {
	firefox := firefox_container.FirefoxPortable{
		Path:           "C:/Users/User/FirefoxPortable",
		ExecutableName: "FirefoxPortable.exe",
	}
}

Usage

TBA

Documentation

Index

Constants

View Source
const (
	CreateListenEvent = 1 << iota
	WriteListenEvent
)

Variables

This section is empty.

Functions

func JoinCookiesToString

func JoinCookiesToString(cookies []http.Cookie) string

Types

type CookieReader

type CookieReader interface {
	Read(path string) ([]http.Cookie, error)
}

type CookiesSqliteCookieReader

type CookiesSqliteCookieReader struct{}

CookiesSqliteCookieReader reads the Data/profile/cookies.sqlite file

func (CookiesSqliteCookieReader) Read

type FirefoxLoadOptions

type FirefoxLoadOptions struct {
	// OpenBrowser decides whether the Firefox Portable executable should be launched so that the user can enter their
	// credential data manually.
	//
	// The executable is launched only if there is no authentication token stored locally or if the existing token is
	// already expired.
	OpenBrowser bool

	// Logger is the logger to be used during the load operation.
	Logger *log.Logger

	// OnStartListening is called when the load operation starts to listen the authentication token file for changes.
	//
	// If there is an authentication token stored locally, and it's not expired, this callback is never called.
	OnStartListening func()
}

type FirefoxPortable

type FirefoxPortable struct {
	Path           string
	ExecutableName string
}

func (FirefoxPortable) ExecutablePath

func (f FirefoxPortable) ExecutablePath() string

func (FirefoxPortable) Load

func (f FirefoxPortable) Load(extractor TokenExtractor, options FirefoxLoadOptions) (string, error)

type Jsonlz4CookieReader

type Jsonlz4CookieReader struct{}

Jsonlz4CookieReader reads the Data/profile/sessionstore-backups/recovery.jsonlz4 file

func (Jsonlz4CookieReader) Read

func (r Jsonlz4CookieReader) Read(path string) ([]http.Cookie, error)

type TokenExtractor

type TokenExtractor interface {
	// GetListenEvent should return to which directory listening event (create or update) the driver should react to.
	GetListenEvent() TokenExtractorListenEvent

	// GetLoginUrl should return a URL that the user can visit so that they can enter their credential data manually.
	GetLoginUrl() *url.URL

	// GetFilePath should return the path of the file where the authentication token will be extracted.
	//
	// The returned path should be relative to the Firefox Portable root directory.
	GetFilePath() string

	// Parse should, given its path, read a file that has the same format as the file pointed by GetFilePath and return
	// the relevant authentication token contained in it.
	Parse(path string) (string, error)

	// Validate should, given an authentication token, check if it's valid or already expired.
	//
	// A token is considered expired if using it on a request raises 401 Unauthorized or 403 Forbidden, where it used to
	// return a 200-like HTTP code at some point in the past.
	Validate(token string) (bool, error)
}

type TokenExtractorListenEvent

type TokenExtractorListenEvent int

Jump to

Keyboard shortcuts

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