Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung | |||
| de:modul:ffit:3-jahr:java:learningunits:lu06:a [2025/09/23 00:08] – apeter | de:modul:ffit:3-jahr:java:learningunits:lu06:a [2025/09/23 00:10] (aktuell) – apeter | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== LU06a - Webtoken | + | ====== LU06a - Webtoken ====== |
| ==== Übersicht ==== | ==== Übersicht ==== | ||
| Zeile 16: | Zeile 16: | ||
| {{: | {{: | ||
| - | |||
| - | ==== Login ==== | ||
| - | |||
| - | **Anforderung 6**: Ein Benutzer in der Datenbank soll sich via ''/ | ||
| - | |||
| - | Sie erhalten die JWT-Funktionalitäten mit dem Commit '' | ||
| - | |||
| - | Die Implementation könnte grob so aussehen: | ||
| - | |||
| - | <code java> | ||
| - | var json = ctx.bodyValidator(Map.class) | ||
| - | .check(m -> m.containsKey(" | ||
| - | .check(m -> m.containsKey(" | ||
| - | .get(); | ||
| - | |||
| - | String inputEmail = (String) json.get(" | ||
| - | String inputPassword = (String) json.get(" | ||
| - | |||
| - | ... // TODO: find user in database with given email | ||
| - | |||
| - | byte[] storedSalt = Base64.getDecoder().decode(user.getPasswordSalt()); | ||
| - | byte[] storedHash = Base64.getDecoder().decode(user.getPasswordHash()); | ||
| - | |||
| - | if (PasswordHandler.verifyPassword(inputPassword, | ||
| - | String jwt = JwtHandler.createJwt(inputEmail, | ||
| - | ctx.json(Map.of(" | ||
| - | return; | ||
| - | } | ||
| - | |||
| - | ... | ||
| - | |||
| - | // TODO: Use the same error message if the user is not found and if the password is wrong | ||
| - | ctx.status(401).json(Map.of(" | ||
| - | </ | ||
| - | |||
| - | Mit Postman können Sie Ihre API testen. | ||
| - | |||
| - | {{: | ||
| - | |||
| - | {{: | ||
| - | |||
| - | Analysieren Sie das zurückgelieferte JWT auf https:// | ||
| - | |||