Documentation ¶
Overview ¶
mozcookiejar gives access to cookies stored in SQLite by Mozilla products.
The general idea is that you can log into some website via Firefox (or whatever) and then have your CLI tools effectively be logged in as well.
It is up to you to create a cookie jar and to connect to the SQLite database. The example below should make it clear how to safely and correctly do that. I have tested the github.com/mattn/go-sqlite3 SQLite driver, but I am pretty sure any of the various SQLite drivers will work.
This library does not support any of the following Cookie fields:
- MaxAge
- HttpOnly
- Raw
- Unparsed
See documentation for the underlying format here: http://kb.mozillazine.org/Cookies.sqlite
Example ¶
package main import ( "database/sql" "fmt" "io" "net/http" "net/http/cookiejar" "os" "github.com/frioux/mozcookiejar" _ "github.com/mattn/go-sqlite3" "golang.org/x/net/publicsuffix" ) // sqlite3 required func main() { jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) if err != nil { fmt.Fprintf(os.Stderr, "Failed to build cookies: %s\n", err) os.Exit(1) } db, err := sql.Open("sqlite3", os.Getenv("MOZ_COOKIEJAR")) if err != nil { fmt.Fprintf(os.Stderr, "Failed to open db: %s\n", err) os.Exit(1) } defer db.Close() err = mozcookiejar.LoadIntoJar(db, jar) if err != nil { fmt.Fprintf(os.Stderr, "Failed to load cookies: %s\n", err) os.Exit(1) } ua := http.Client{Jar: jar} resp, err := ua.Get("https://some.authenticated.com/website") if err != nil { fmt.Fprintf(os.Stderr, "Failed to fetch page: %s\n", err) os.Exit(1) } io.Copy(os.Stdout, resp.Body) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.