This project was generated with Spring Initializr.
Follow along with the tutorial from Phase Two.
To skip this section, use Phase Two to setup a free Keycloak hosted in the cloud. Instructions below assume using the local instance, but values can easily be changed to match the cloud instance.
- Start Keycloak server using
docker-compose up -d
- Go to
http://localhost:8888/auth
and login using usernameadmin
and passwordadmin
- Create a realm
demo-realm
- Create a public client
demo-spa
and add redirectUrihttp://localhost:4200/*
and Web Originshttp://localhost:4200
- Create a realm role
user
- Create a
test
user and assign theuser
role to it. Add password credentials to thetest
user.
- Open another terminal. Go to
./angularclient
folder. Runnpm i
and start the Angular app usingnpm run start
. - Open the browser to
http://localhost:4200/
. After login theaccessToken
should be present in thelocalStorage
of the browser. View this by opening a Web console and typinglocalStorage
to view its value. - Use access token to access secured endpoints:
- Run
./gradlew bootRun
to start the SpringBoot application in a terminal. - Directly hit the Spring application's API interface. Pull the
accessToken
fromlocalStorage
.
curl --location 'http://localhost:8080/api/test/anonymous' \
--header 'Authorization: Bearer {{$access_token}}'
curl --location 'http://localhost:8080/api/test/user' \
--header 'Authorization: Bearer {{$access_token}}'