Skip to content

Commit

Permalink
Add email to JWT
Browse files Browse the repository at this point in the history
GitOrigin-RevId: d3140dd2744b458157f291e69550e790e019004b
  • Loading branch information
pdesgarets authored and Gitlab-CI committed Dec 4, 2024
1 parent 0966ef1 commit 23ac684
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions back/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
## 2.30.0
- Add email and enabbled fields in user CRUD
- Add email in generated JWT

## 2.29.0
### Added
- Add OIDC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public ResponseEntity<String> launch(

String localToken = jwtTokenProvider
.generateToken(
user.getEmail(), TokenOrigin.LTI
user.getUsername(), user.getEmail(), TokenOrigin.LTI
);

activityLogger.log(LogAction.USER_LOGIN_LTI, user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public JwtTokenProvider(
verifier = JWT.require(algorithmHS256).build();
}

public String generateToken(String username, TokenOrigin tokenOrigin) {
public String generateToken(String username, String email, TokenOrigin tokenOrigin) {

Date now = new Date();
Date expiryDate = new Date(now.getTime() + jwtExpirationInMs);
Expand All @@ -45,6 +45,7 @@ public String generateToken(String username, TokenOrigin tokenOrigin) {
.withExpiresAt(expiryDate)
.withIssuedAt(now)
.withSubject(username)
.withClaim("email", email)
.withClaim("origin", tokenOrigin.toString())
.sign(algorithmHS256);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String getLocalTokenFromOIDCToken(String oidcToken) {
myUserDetailsService.ensureTeacher(user);
}

String jwtToken = jwtTokenProvider.generateToken(user.getEmail(), TokenOrigin.OIDC);
String jwtToken = jwtTokenProvider.generateToken(user.getUsername(), user.getEmail(), TokenOrigin.OIDC);
logger.debug("JWT token: " + jwtToken);
activityLogger.log(LogAction.USER_LOGIN_OIDC, user);
return jwtToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public ResponseEntity<?> login(

String jwtToken = jwtTokenProvider
.generateToken(
user.getEmail(), TokenOrigin.CAS
user.getUsername(), user.getEmail(), TokenOrigin.CAS
);
logger.debug("JWT token: " + jwtToken);
activityLogger.log(LogAction.USER_LOGIN_CAS, user);
Expand Down

0 comments on commit 23ac684

Please sign in to comment.