Auth Service in Spring Boot banner

Auth Service in Spring Boot

6 devlogs
8h 32m 44s

My first Spring Boot project. A simple authentication server.

This project uses AI

some autocompletion by Github Copilot but not much. i mostly just used some Medium.com blogs about authentication in spring boot: one about security filters and another about jwts. the README was ai generated with some tweaks

Loading README...

mattseq

added a initialization endpoint so that an admin can be created when the service first starts. had to make this bc only admins have permissions to create users but when the service first starts and there are no admins, its otherwise impossible to create an admin, which results in a weird permission paradox. the initialization endpoint only works when there’s no admins already in the db. i also added a README, finally.

Attachment
0
mattseq

took me like 30 minutes to switch from h2 to postgres. it was so stupid bc i put a colon instead of a slash in the database url. i was just running a postgres docker container on my rpi instead of the laptop im using. eventually i should make a docker-compose.yml to include the db. it was surprisingly easy to switch databases, all you need to do is change the url name and add the postgres driver as a dependency.

Attachment
0
mattseq

added jwt auth filter. basically it just extracts stuff like roles from the jwt and passes it on as SecurityContext and in my SecurityConfig i can use methods like .hasRole() on specific URIs. i also included claims in the jwt so that it contains id, username, roles, etc. and it also has specific extract methods but i might combine those into one that returns a User.

Attachment
Attachment
0
mattseq

its now hashing passwords with Bcrypt. here’s a picture of me using the h2 console to check what the passwords stored as

Attachment
0
mattseq

renamed the project to auth-service. i also implemented the login and verify endpoints using jwts. i also started using postman for the first time to test my api, since im on windows and used to ssh into my rpi just to use curl. im still not hashing passwords yet lol. heres a picture of my postman flow that i used to test

Attachment
0
mattseq

started by watching Mosh’s spring boot tutorial. dont really know how im supposed to use some of that stuff though. got started with creating a database with spring jpa. just using h2 for now, i’ll switch to postgres later or something. all i did was get the repository and basic crud working and user methods working. ran into a small issue with spring security automatically asking for authentication at every endpoint. next i need to create jwt auth, and use the security filter stuff provided by spring security to block certain endpoints. then i’ll create roles and make the verify endpoint

Attachment
0