googleauth

package
v6.7.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

Google Authentication

router := mux.NewRouter()

key := "my-secret-key"
sessionStorage := sessions.NewCookieStore([]byte(key))
sessionStorage.MaxAge(86400 * 2)
sessionStorage.Options.Path = "/"
sessionStorage.Options.HttpOnly = true
sessionStorage.Options.Secure = false

googleAuthConfig := googleauth.GoogleAuthConfig{
  SessionAuthConfig: auth.SessionAuthConfig{
    AuthFailedHandler: func(w http.ResponseWriter, r *http.Request, err error) {
      nerdweb.WriteJSON(logger, w, http.StatusUnauthorized, map[string]interface{}{
        "success": false,
        "error":   err.Error(),
      })
    },
    AuthSuccessHandler: func(w http.ResponseWriter, r *http.Request, user goth.User) {
      logger.WithField("user", user).Info("Successful login")
      http.Redirect(w, r, "/view-logs", http.StatusTemporaryRedirect)
    },
    ErrorPath:         "/unauthorized",
    ExcludedPaths:     []string{"/", "/unauthorized", "/static", "/auth", "/main.js", "/index.html", "/version"},
    HTMLResponsePaths: []string{"/view-logs", "/manage-servers", "/edit-server"},
    SessionName:       "fireplacelogging",
    Store:             sessionStorage,
  },
  GoogleClientID:     config.GoogleClientID,
  GoogleClientSecret: config.GoogleClientSecret,
  GoogleRedirectURI:  config.GoogleRedirectURI,
}

googleauth.Setup(router, googleAuthConfig, logger)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

func Setup(router *mux.Router, config GoogleAuthConfig, logger *logrus.Entry)

Types

type GoogleAuthConfig

type GoogleAuthConfig struct {
	auth.SessionAuthConfig

	GoogleClientID     string
	GoogleClientSecret string
	GoogleRedirectURI  string
}

Jump to

Keyboard shortcuts

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