Documentation ¶
Overview ¶
Package google provides you access to Google's OAuth2 infrastructure. The implementation is based on this blog post: http://skarlso.github.io/2016/06/12/google-signin-with-go/
Index ¶
- func Auth() gin.HandlerFunc
- func GetLoginURL(state string) string
- func LoginHandler(ctx *gin.Context)
- func Session(name string) gin.HandlerFunc
- func Setup(redirectURL, credFile string, scopes []string, secret []byte)
- func SetupFromString(redirectURL, clientID string, clientSecret string, scopes []string, ...)
- func WithLoginURL(s string) error
- type Credentials
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Auth ¶
func Auth() gin.HandlerFunc
Auth is the google authorization middleware. You can use them to protect a routergroup. Example:
private.Use(google.Auth()) private.GET("/", UserInfoHandler) private.GET("/api", func(ctx *gin.Context) { ctx.JSON(200, gin.H{"message": "Hello from private for groups"}) }) // Requires google oauth pkg to be imported as `goauth "google.golang.org/api/oauth2/v2"` func UserInfoHandler(ctx *gin.Context) { var ( res goauth.Userinfo ok bool ) val := ctx.MustGet("user") if res, ok = val.(goauth.Userinfo); !ok { res = goauth.Userinfo{Name: "no user"} } ctx.JSON(http.StatusOK, gin.H{"Hello": "from private", "user": res.Email}) }
func GetLoginURL ¶
func LoginHandler ¶
func Session ¶
func Session(name string) gin.HandlerFunc
func SetupFromString ¶ added in v1.5.6
func SetupFromString(redirectURL, clientID string, clientSecret string, scopes []string, secret []byte)
SetupFromString accepts string values for ouath2 Configs
func WithLoginURL ¶ added in v1.5.6
Types ¶
type Credentials ¶
Credentials stores google client-ids.
Click to show internal directories.
Click to hide internal directories.