https://github.com/abarhub/spring-boot-oauth-client
https://github.com/abarhub/spring-boot-oauth-client
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/abarhub/spring-boot-oauth-client
- Owner: abarhub
- Created: 2021-01-01T10:05:00.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-06T21:46:27.000Z (over 3 years ago)
- Last Synced: 2023-03-25T15:30:54.328Z (over 3 years ago)
- Language: HTML
- Size: 2.49 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spring-boot-oauth-client
Implémentation d'OpenId Connect avec KeyCloak
C'est avec KeyCloak 11.0.3.
Pour Spring, il faut ajouter la dependance :
```xml
org.springframework.boot
spring-boot-starter-oauth2-resource-server
```
Il faut aussi ajouter en configuration :
```yml
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://localhost:8180/auth/realms/test1
jwk-set-uri: http://localhost:8180/auth/realms/test1/protocol/openid-connect/certs
```
Pour Angular, il faut utiliser la librairie angular-oauth2-oidc.
Sites :
https://manfredsteyer.github.io/angular-oauth2-oidc/docs/
https://github.com/manfredsteyer/angular-oauth2-oidc
https://www.npmjs.com/package/angular-oauth2-oidc
L'authentifiation avec Angular doit être fait avec code flow + PKCE, et pas avec implicit flow, qui est moins sécurisé.
Pour l'authentification, :
1) Angular redirige vers KeyCloak,
2) KeyCloak fait l'authentification et redirige vers le navigateur
3) le navigateur enregistre le token et l'utilise pour appeler le endpoind spring
4) Spring vérifie le token et récupère de keycloak les informations de l'utilisateur et crée la session
5) le endpoint fait son traitement
Le vériviation du token dans Spring n'est fait qu'une seule fois, elle n'est plus faite apres.
Dans Angular, il faut lui dire de faire le rafrechissement régulièrement.
https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/refreshing-a-token.html
Dans KeyCloak, il faut définir le temps maximum de rafrechissement du token
Si Spring a besoin d'accéder a des info de KeyCloak, il ne doit pas utiliser le token venant d'Angular,
mais faire la propre connection avec login/mot de passe.
Aides :
https://www.baeldung.com/spring-webclient-oauth2
https://www.appsdeveloperblog.com/keycloak-rest-api-create-a-new-user/
http://localhost:8180/auth/
http://localhost:4200/
https://stackoverflow.com/questions/56743109/keycloak-create-admin-user-in-a-realm
https://gist.github.com/luciddreamz/83a888eedd9274b4045a3ab8af064faa
https://www.baeldung.com/postman-keycloak-endpoints
https://www.keycloak.org/docs-api/5.0/rest-api/index.html#_roles_resource