-
Notifications
You must be signed in to change notification settings - Fork 589
Description
So I'm trying to add a /register and /login endpoint that accepts a JSON payload with the email/password credentials of the user, and looking at the docs and the API, it's not readily apparent exactly what I should do to authenticate the user and issue a token.
The example is awesome for showing how to be an oauth server, but I'd like my local login flow to issue the token as well as any outside auth providers via oauth.
I'm certain that the library is capable of this, I'm just kind of struggling for the implementation.
func (client *localAuthClient) AuthenticateUser(email string, password string) (string, error) {
c := client.DB.C("users")
user := &models.User{}
err := c.Find(bson.M{ "email": email }).One(user)
if err != nil {
return "", err
}
if comparePasswords(user.Password, []byte(password)) {
return user.ID.Hex(), nil
}
return "", errors.New("email/password combination is not a match")
}
And in my main.go:
srv.SetPasswordAuthorizationHandler(localAuthClient.AuthenticateUser)
But I'm having a disconnect at this point. How do I instruct the API to run my password authentication flow in an endpoint that will generate a token (a JWT specifically, but that looks straightforward enough)?