https://github.com/mashiike/google-oidc-middleware
Google OIDC Middleware for golang
https://github.com/mashiike/google-oidc-middleware
Last synced: 3 months ago
JSON representation
Google OIDC Middleware for golang
- Host: GitHub
- URL: https://github.com/mashiike/google-oidc-middleware
- Owner: mashiike
- License: mit
- Created: 2022-12-20T05:10:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-27T21:03:37.000Z (about 2 years ago)
- Last Synced: 2024-05-01T16:15:22.492Z (about 1 year ago)
- Language: Go
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# google-oidc-middleware
[](https://godoc.org/github.com/mashiike/google-oidc-middleware)


[](https://goreportcard.com/report/mashiike/google-oidc-middleware)
[](https://github.com/mashiike/google-oidc-middleware/blob/master/LICENSE)Google OIDC Middleware for golang
## Requirements
* Go 1.19 or higher. support the 3 latest versions of Go.## Usage
sample go code
```go
package mainimport (
"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)
}
}
```