Sign inSign up

j0rsa/jwt-auth

By j0rsa

•Updated over 5 years ago

Image
0

938

j0rsa/jwt-auth repository overview

⁠JWT Authentication service

This is a simple service to authenticate users and check their authentication information according to JWT validity (signature, expiration, sub)

Docker Cloud Automated build Docker Cloud Build Status

Base Docker image scratch Image Size MicroBadger Layers

CodeFactor

⁠Endpoints

MethodURLDescription
GET/healthHealthcheck which returns Code 200
POST/auth/tokenGet JWT token by passing user credentials { "user": "name", "password": "secret"}
POST/auth/refreshRefresh token with a new one by passing the old valid one { "token": "eyJhbGciOiJIUz..." }
POST/auth/checkChecks the token and returns code 200 with Headers: X-Auth-Id with user id and X-Auth-User with user name

⁠Environment variables

VariableDefault valueDescription
RUST_LOGinfodefines the log level of app
DB_HOSTlocalhostPostgres host
DB_PORT5432Postgres port
DB_USERpostgresPostgres user
DB_PASSWORDpostgresPostgres password
DB_NAMEpostgresDatabase name
DB_QUERY_USER_IDidId column name in users table
DB_QUERY_USER_NAMEnameUsername column name in users table
DB_QUERY_USER_PASSWORDpasswordPassword column name in users table
DB_QUERY_USERS_TABLEusersusers table
BIND_ADDRESS0.0.0.0Address of web server to listen connections
BIND_PORT8080Port of web server to listen connections
PASSWORD_CHECK_TYPERAWType to compare passwords with the one from DB (values: RAW, SHA256, SHA512, BCRYPT)
JWT_SECRET--JWT HS256 Secret Key
JWT_ISS""iss (issuer): Issuer of the JWT
JWT_AUD""aud (audience): Recipient for which the JWT is intended
JWT_EXP_DAYS30exp (expiration time): Time in days after which the JWT expires
JWT_NBF_DAYS0nbf (not before time): Time in days before which the JWT must not be accepted for processing
JWT_LEEWAY_SEC0leeway (in seconds) to the exp, iat and nbf validation to account for clock skew

⁠Build

⁠Build release locally

cargo build --release

⁠Build release in docker and prepare an image

docker build -t j0rsa/jwt-auth .

ref: https://shaneutt.com/blog/rust-fast-small-docker-image-builds/⁠

ref: https://medium.com/@gdiener/how-to-build-a-smaller-docker-image-76779e18d48a⁠

⁠Troubleshooting

⁠Inspect image filesystem

docker run --rm -it <image name or id> sh

⁠Test run

docker run --rm -it jwt-auth

Tag summary

Content type

Image

Digest

Size

3.6 MB

Last updated

over 5 years ago

docker pull j0rsa/jwt-auth