https://github.com/borud/gin
Simple Google Login
https://github.com/borud/gin
Last synced: 11 months ago
JSON representation
Simple Google Login
- Host: GitHub
- URL: https://github.com/borud/gin
- Owner: borud
- License: apache-2.0
- Created: 2020-07-12T17:26:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-24T21:43:02.000Z (almost 6 years ago)
- Last Synced: 2025-07-08T23:03:23.313Z (11 months ago)
- Language: Go
- Size: 14.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple Google Login
[](https://godoc.org/github.com/borud/gin/pkg/auth)
**This is a work in progress.**
I got tired of baroque libraries that pull inn all manner of unwanted
cruft so I made a bare bones library to log in using Google. This code
takes care of only the Google login.
Import the following package
"github.com/borud/gin/pkg/auth"
## Abbreviated example
Here is an abbreviated example of how to use this module. The
`loginCallback` is where you would create the session etc, but since
people use different libraries for handling sessions we leave this
part up to you.
package main
import (
"fmt"
"net/http"
"os"
"github.com/borud/gin/pkg/auth"
)
func main() {
googleAuth := auth.New(&auth.GoogleAuthConfig{
ClientID: os.Getenv("GOOGLE_CLIENT_ID"),
ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"),
CallbackURL: "http://localhost:3000/google/callback",
LoginCallback: loginCallback,
})
http.HandleFunc("/google/login", googleAuth.GoogleLoginHandler)
http.HandleFunc("/google/callback", googleAuth.GoogleCallbackHandler)
http.ListenAndServe(":3000", nil)
}
func loginCallback(w http.ResponseWriter, r *http.Request, userinfo *auth.Userinfo) {
html := `Hello %s
GOOGLE_CLIENT_SECRET=
You can create your client credentials at:
https://console.developers.google.com/apis/credentials