Categorygithub.com/mashiike/google-oidc-middleware
modulepackage
0.1.0
Repository: https://github.com/mashiike/google-oidc-middleware.git
Documentation: pkg.go.dev

# README

google-oidc-middleware

Documentation Latest GitHub tag Github Actions test Go Report Card License

Google OIDC Middleware for golang

Requirements

  • Go 1.19 or higher. support the 3 latest versions of Go.

Usage

sample go code

package main

import (
	"encoding/json"
	"log"
	"net/http"
	"os"

	googleoidcmiddleware "github.com/mashiike/google-oidc-middleware"
	"github.com/thanhpk/randstr"
)

func main() {
	log.Println("access http://localhost:8080")
	err := http.ListenAndServe("localhost:8080", googleoidcmiddleware.WrapGoogleOIDC(
		http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			claims, ok := googleoidcmiddleware.IDTokenClaims(r.Context())
			if !ok {
				w.WriteHeader(http.StatusForbidden)
				return
			}
			w.WriteHeader(http.StatusOK)
			e := json.NewEncoder(w)
			e.SetEscapeHTML(true)
			e.SetIndent("", "  ")
			e.Encode(claims)
		}),
		(&googleoidcmiddleware.Config{
			ClientID:          os.Getenv("GOOGLE_CLIENT_ID"),
			ClientSecret:      os.Getenv("GOOGLE_CLIENT_SECRET"),
			SessionEncryptKey: randstr.Bytes(32),
			Scopes:            []string{"email"},
		}).WithBaseURL("http://localhost:8080"),
	))
	if err != nil {
		log.Fatalln(err)
	}
}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author