Skip to content

Files

Latest commit

456b9c5 · Dec 20, 2017

History

History

auth

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 9, 2017
Dec 20, 2017
Oct 13, 2017

Authorization (auth) package

This package allows to connect via OAuth2.0 to the arduino.cc system (Hydra)

See test package for an example of usage.

Basic usage

// Just create a new auth object.
authObj := auth.New()
token, err := auth.Token(testUser, testPass)
if err != nil {
	// Handle error
}

// Then use the generated token in your requests, for example:
// Obtain info of my user.
req, err := http.NewRequest("GET", "https://auth.arduino.cc/v1/users/byID/me", nil)
if err != nil {
	// Handle error
}
req.Header.Add("Authorization", "Bearer "+token.Access)
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
	// Handle error
}

// Before your token expires, you can do a refresh to have a new one for the
// same session:
newToken, err := auth.Refresh(token.Access)
if err != nil {
	// Handle error
}