google

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 18 Imported by: 12

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"})
       })

   // 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 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

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

func WithLoginURL(s string) error

Types

type Credentials

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

Credentials stores google client-ids.

Jump to

Keyboard shortcuts

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