go-oauth2 / oauth2

OAuth 2.0 server library for the Go programming language.
https://pkg.go.dev/github.com/go-oauth2/oauth2/v4
MIT License
3.31k stars 563 forks source link

Can I add a callback after login? #217

Open lixh00 opened 2 years ago

lixh00 commented 2 years ago

Can I add a callback after login? such as updating the last login time of the database after login.

realbucksavage commented 2 years ago

Yes you can!

manager := maange.NewDefaultManager()
server := server.NewDefaultServer(manager)

server.SetUserAuthorizationHandler(func(rw http.ResponseWriter, r *http.Request) (string, error) {

    var (
        ctx      = r.Context()
        username = r.FormValue("username")
        password = r.FormValue("password")
    )
    user, err := myAuthenticator.Authenticate(ctx, username, password)
    // handle error

    // update last login time in DB
})