drivers

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AmazonAPIMap = map[string]string{
	"endpoint":     "https://api.amazon.com",
	"userEndpoint": "/user/profile",
}

AmazonAPIMap is the map for API endpoints

View Source
var AmazonDefaultScopes = []string{"profile"}

AmazonDefaultScopes contains the default scopes

View Source
var AmazonUserFn = func(client *http.Client, u *structs.User) {}

AmazonUserFn is a callback to parse additional fields for User

View Source
var AmazonUserMap = map[string]string{
	"user_id": "ID",
	"name":    "FullName",
	"email":   "Email",
}

AmazonUserMap is the map to create the User struct

View Source
var AsanaAPIMap = map[string]string{
	"endpoint":     "https://app.asana.com/api/1.0",
	"userEndpoint": "/users/me?opt_fields=id,name,email,photo",
}

AsanaAPIMap is the map for API endpoints

View Source
var AsanaDefaultScopes = []string{}

AsanaDefaultScopes contains the default scopes

View Source
var AsanaEndpoint = oauth2.Endpoint{
	AuthURL:  "https://app.asana.com/-/oauth_authorize",
	TokenURL: "https://app.asana.com/-/oauth_token",
}

DailyMotionEndpoint is the oAuth endpoint

View Source
var AsanaUserFn = func(client *http.Client, u *structs.User) {
	userData := u.Raw["data"].(map[string]interface{})
	u.ID = fmt.Sprintf("%.0f", userData["id"].(float64))
	u.Email = userData["email"].(string)
	u.FullName = userData["name"].(string)

	if userData["photo"] != nil {
		u.Avatar = userData["photo"].(map[string]interface{})["image_1024x1024"].(string)
	}
}

AsanaUserFn is a callback to parse additional fields for User

View Source
var AsanaUserMap = map[string]string{}

AsanaUserMap is the map to create the User struct

View Source
var BitbucketAPIMap = map[string]string{
	"endpoint":      "https://api.bitbucket.org",
	"userEndpoint":  "/2.0/user",
	"emailEndpoint": "/2.0/user/emails",
}

BitbucketAPIMap is the map for API endpoints

View Source
var BitbucketDefaultScopes = []string{"account", "email"}

BitbucketDefaultScopes contains the default scopes

View Source
var BitbucketUserFn = func(client *http.Client, u *structs.User) {

	u.Avatar = u.Raw["links"].(map[string]interface{})["avatar"].(map[string]interface{})["href"].(string)

	req, err := client.Get(BitbucketAPIMap["endpoint"] + BitbucketAPIMap["emailEndpoint"])
	if err != nil {
		return
	}

	defer req.Body.Close()
	res, _ := ioutil.ReadAll(req.Body)
	data, err := jsonDecode(res)
	if err != nil {
		return
	}

	u.Email = data["values"].([]interface{})[0].(map[string]interface{})["email"].(string)
}

BitbucketUserFn is a callback to parse additional fields for User

View Source
var BitbucketUserMap = map[string]string{
	"account_id":   "ID",
	"username":     "Username",
	"display_name": "FullName",
}

BitbucketUserMap is the map to create the User struct

View Source
var FacebookAPIMap = map[string]string{
	"endpoint":     "https://graph.facebook.com",
	"userEndpoint": "/me?fields=id,name,first_name,last_name,email",
}

FacebookAPIMap is the map for API endpoints

View Source
var FacebookDefaultScopes = []string{"email"}

FacebookDefaultScopes contains the default scopes

View Source
var FacebookUserFn = func(client *http.Client, u *structs.User) {
	u.Avatar = FacebookAPIMap["endpoint"] + "/v2.8/" + u.ID + "/picture?width=800"
}

FacebookUserFn is a callback to parse additional fields for User

View Source
var FacebookUserMap = map[string]string{
	"id":         "ID",
	"email":      "Email",
	"name":       "FullName",
	"first_name": "FirstName",
	"last_name":  "LastName",
}

FacebookUserMap is the map to create the User struct

View Source
var FoursquareAPIMap = map[string]string{
	"endpoint":     "https://api.foursquare.com",
	"userEndpoint": "/v2/users/self?oauth_token=%ACCESS_TOKEN&v=20171220",
}

FoursquareAPIMap is the map for API endpoints

View Source
var FoursquareDefaultScopes = []string{}

FoursquareDefaultScopes contains the default scopes

View Source
var FoursquareUserFn = func(client *http.Client, u *structs.User) {
	user := u.Raw["response"].(map[string]interface{})["user"].(map[string]interface{})

	u.ID = user["id"].(string)
	u.FirstName = user["firstName"].(string)
	u.LastName = user["lastName"].(string)
	u.FullName = u.FirstName + " " + u.LastName

	if email, ok := user["contact"].(map[string]interface{})["email"]; ok {
		u.Email = email.(string)
	}
	if avatarPrefix, ok := user["photo"].(map[string]interface{})["prefix"]; ok {
		if avatarSuffix, ok2 := user["photo"].(map[string]interface{})["suffix"]; ok2 {
			u.Avatar = avatarPrefix.(string) + "original" + avatarSuffix.(string)
		}
	}
}

FoursquareUserFn is a callback to parse additional fields for User

View Source
var FoursquareUserMap = map[string]string{}

FoursquareUserMap is the map to create the User struct

View Source
var GithubAPIMap = map[string]string{
	"endpoint":      "https://api.github.com",
	"userEndpoint":  "/user",
	"emailEndpoint": "/user/emails",
}

GithubAPIMap is the map for API endpoints

View Source
var GithubDefaultScopes = []string{"user:email"}

GithubDefaultScopes contains the default scopes

View Source
var GithubUserFn = func(client *http.Client, u *structs.User) {
	// Used to parse the email from response
	type additionalEmail struct {
		Email string `json:"email"`
	}
	var email []additionalEmail

	if u.Email == "<nil>" {

		req, err := client.Get(GithubAPIMap["endpoint"] + GithubAPIMap["emailEndpoint"])
		if err != nil {
			return
		}

		defer req.Body.Close()
		err = json.NewDecoder(req.Body).Decode(&email)
		if err != nil {
			return
		}

		u.Email = email[0].Email
	}
}

GithubUserFn is a callback to parse additional fields for User

View Source
var GithubUserMap = map[string]string{
	"id":         "ID",
	"email":      "Email",
	"login":      "Username",
	"avatar_url": "Avatar",
	"name":       "FullName",
}

GithubUserMap is the map to create the User struct

View Source
var GoogleAPIMap = map[string]string{
	"endpoint":     "https://www.googleapis.com",
	"userEndpoint": "/oauth2/v2/userinfo",
}

GoogleAPIMap is the map for API endpoints

View Source
var GoogleDefaultScopes = []string{"profile", "email"}

GoogleDefaultScopes contains the default scopes

View Source
var GoogleUserFn = func(client *http.Client, u *structs.User) {}

GoogleUserFn is a callback to parse additional fields for User

View Source
var GoogleUserMap = map[string]string{
	"id":          "ID",
	"email":       "Email",
	"name":        "FullName",
	"given_name":  "FirstName",
	"family_name": "LastName",
	"picture":     "Avatar",
}

GoogleUserMap is the map to create the User struct

View Source
var LinkedInAPIMap = map[string]string{
	"endpoint":      "https://api.linkedin.com",
	"userEndpoint":  "/v2/me",
	"emailEndpoint": "/v2/emailAddress?q=members&projection=(elements*(handle~))",
}

LinkedInAPIMap is the map for API endpoints

View Source
var LinkedInDefaultScopes = []string{"r_emailaddress", "r_liteprofile"}

LinkedInDefaultScopes contains the default scopes

View Source
var LinkedInUserFn = func(client *http.Client, u *structs.User) {
	defer func() {
		if r := recover(); r != nil {
			fmt.Fprintln(os.Stderr, r)
		}
	}()
	u.FullName = u.FirstName + " " + u.LastName

	req, err := client.Get(LinkedInAPIMap["endpoint"] + LinkedInAPIMap["emailEndpoint"])
	if err != nil {
		return
	}
	defer req.Body.Close()

	email := make(map[string]interface{})
	err = json.NewDecoder(req.Body).Decode(&email)
	if err != nil {
		return
	}

	u.Email = email["elements"].([]interface{})[0].(map[string]interface{})["handle~"].(map[string]interface{})["emailAddress"].(string)

}

LinkedInUserFn is a callback to parse additional fields for User

View Source
var LinkedInUserMap = map[string]string{
	"id":                 "ID",
	"localizedFirstName": "FirstName",
	"localizedLastName":  "LastName",
	"vanityName":         "_",
	"firstName":          "_",
	"lastName":           "_",
	"formattedName":      "_",
	"emailAddress":       "Email",
	"pictureUrl":         "Avatar",
}

LinkedInUserMap is the map to create the User struct

View Source
var SlackAPIMap = map[string]string{
	"endpoint":     "https://slack.com/api",
	"userEndpoint": "/users.profile.get",
	"authEndpoint": "/auth.test",
}

SlackAPIMap is the map for API endpoints

View Source
var SlackDefaultScopes = []string{"users.profile:read"}

SlackDefaultScopes contains the default scopes

View Source
var SlackUserFn = func(client *http.Client, u *structs.User) {

	req, err := client.Get(SlackAPIMap["endpoint"] + SlackAPIMap["authEndpoint"])
	if err != nil {
		return
	}

	defer req.Body.Close()
	res, _ := ioutil.ReadAll(req.Body)
	data, err := jsonDecode(res)
	if err != nil {
		return
	}

	u.ID = data["user_id"].(string)

	userInfo := u.Raw["profile"].(map[string]interface{})
	u.Username = userInfo["display_name"].(string)
	u.FullName = userInfo["real_name"].(string)
	u.FirstName = userInfo["first_name"].(string)
	u.LastName = userInfo["last_name"].(string)
	u.Email = userInfo["email"].(string)
	u.Avatar = userInfo["image_original"].(string)
}

SlackUserFn is a callback to parse additional fields for User

View Source
var SlackUserMap = map[string]string{
	"real_name":      "FullName",
	"first_name":     "FirstName",
	"last_name":      "LastName",
	"email":          "Email",
	"image_original": "Avatar",
}

SlackUserMap is the map to create the User struct

Functions

func InitializeDrivers

func InitializeDrivers(register func(driver string, defaultscopes []string, callback func(client *http.Client, u *structs.User), endpoint oauth2.Endpoint, apimap, usermap map[string]string))

InitializeDrivers adds all the drivers to the register func

Types

This section is empty.

Jump to

Keyboard shortcuts

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