Add support for openid with github and facebook

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-10-04 11:40:56 -03:00
parent eebe638227
commit 4c034812d2
25 changed files with 712 additions and 251 deletions

40
handlers/cookie_id.go Normal file
View File

@@ -0,0 +1,40 @@
package handlers
import (
"net/http"
"github.com/play-with-docker/play-with-docker/config"
)
type CookieID struct {
Id string `json:"id"`
UserName string `json:"user_name"`
UserAvatar string `json:"user_avatar"`
}
func (c *CookieID) SetCookie(rw http.ResponseWriter) error {
if encoded, err := config.SecureCookie.Encode("id", c); err == nil {
cookie := &http.Cookie{
Name: "id",
Value: encoded,
Path: "/",
Secure: config.UseLetsEncrypt,
}
http.SetCookie(rw, cookie)
} else {
return err
}
return nil
}
func ReadCookie(r *http.Request) (*CookieID, error) {
if cookie, err := r.Cookie("id"); err == nil {
value := &CookieID{}
if err = config.SecureCookie.Decode("id", cookie.Value, &value); err == nil {
return value, nil
} else {
return nil, err
}
} else {
return nil, err
}
}