google

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: MIT Imports: 11 Imported by: 0

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

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"})
    })
func UserInfoHandler(ctx *gin.Context) {
    ctx.JSON(http.StatusOK, gin.H{"Hello": "from private", "user": ctx.MustGet("user").(google.User)})
}

func GetLoginURL

func GetLoginURL(state string) string

func LoginHandler

func LoginHandler(ctx *gin.Context)

func Session

func Session(name string) gin.HandlerFunc

func Setup

func Setup(redirectURL, credFile string, scopes []string, secret []byte)

Setup the authorization path

Types

type Credentials

type Credentials struct {
	ClientID     string `json:"clientid"`
	ClientSecret string `json:"secret"`
}

Credentials stores google client-ids.

type User

type User struct {
	Sub           string `json:"sub"`
	Name          string `json:"name"`
	GivenName     string `json:"given_name"`
	FamilyName    string `json:"family_name"`
	Profile       string `json:"profile"`
	Picture       string `json:"picture"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	Gender        string `json:"gender"`
	Hd            string `json:"hd"`
}

User is a retrieved and authenticated user.

Jump to

Keyboard shortcuts

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