Skip to content

So how exactly does the SetPasswordAuthorizationHandler work? #100

@mikepc

Description

@mikepc

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)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions