jamesmawm / golang-user-microservice

Create a micro service for handling user accounts.
MIT License
7 stars 6 forks source link

Add JWT token support #8

Open jamesmawm opened 4 years ago

jamesmawm commented 4 years ago

Add support to generate and validate JWT tokens. JWT tokens are generated when a user logs in with a username and password.

karimelazzouni commented 4 years ago

Will work on this 😃

karimelazzouni commented 4 years ago

@jamesmawm I don't exactly understand the requirement here. The application doesn't have an authentication flow to login with username and password. Is is expected to be a part of this issue? Or should the JWT token be generated when hitting the ping API endpoint?

jamesmawm commented 4 years ago

You're right, as this issue #8 is only applicable when the endpoints in issue #4 are implemented. In the interim, you can add in the supporting JWT functions using example/dummy strings. Assume that some username and password to sent to a /api/login endpoint, and assuming the user is successfully authenticated, generate and return a JWT token. An example payload could be:

{
  "sub": "1234567890",
  "name": "John Doe",
}

After the endpoints in #4 are implemented, we can integrate with your JWT support to produce a working solution.

karimelazzouni commented 4 years ago

Hey @jamesmawm , spent a couple of hours today trying to get the latest version of the service to run on docker-compose but couldn't.

Firstly had problems with go mod download because the go.mod file was omitted from the docker image; fixed that by removing go.mod and go.sum from the .dockerignore file.

However, now the service would never start when running docker-compose up -d with the following very vague error message

ERROR: Service 'user-service' failed to build: The command '/bin/sh -c go mod download &&    go mod vendor &&    go build -v &&    rm -rf vendor &&    mv golang-user-microservice server' returned a non-zero code: 2

I am also seeing the same error when just trying out docker build ..

Are you able to run the docker container locally? Is the README missing any dependencies?

jamesmawm commented 4 years ago

Hey @karimelazzouni, thanks for bringing this across! I got the same errors too. I've applied your fix, along with adding a gcc dependency needed by some of the packages, in PR #21. After pulling the latest from the main branch, your docker should be good running up.