-
Notifications
You must be signed in to change notification settings - Fork 32
Jwttoken add in header #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,4 +49,27 @@ public static HttpEntity<Object> createRequestEntity(Object body, String authori | |
| return new HttpEntity<>(body, headers); | ||
| } | ||
|
|
||
| public static void getJwttokenFromHeaders(HttpHeaders headers) { | ||
| ServletRequestAttributes servletRequestAttributes = ((ServletRequestAttributes) RequestContextHolder | ||
| .getRequestAttributes()); | ||
|
|
||
| HttpServletRequest requestHeader = servletRequestAttributes.getRequest(); | ||
| String jwtTokenFromCookie = null; | ||
| try { | ||
| jwtTokenFromCookie = CookieUtil.getJwtTokenFromCookie(requestHeader); | ||
|
|
||
| } catch (Exception e) { | ||
| logger.error("Error while getting jwtToken from Cookie" + e.getMessage()); | ||
| } | ||
| if (null != UserAgentContext.getUserAgent()) { | ||
| headers.add(HttpHeaders.USER_AGENT, UserAgentContext.getUserAgent()); | ||
| } | ||
| if (null != jwtTokenFromCookie) { | ||
| headers.add(Constants.JWT_TOKEN, jwtTokenFromCookie); | ||
| } else if (null != requestHeader.getHeader(Constants.JWT_TOKEN)) { | ||
| headers.add(Constants.JWT_TOKEN, requestHeader.getHeader(Constants.JWT_TOKEN)); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| } | ||
|
Comment on lines
+57
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Consider refactoring to eliminate code duplication. This method contains nearly identical logic to the existing Consider extracting the common JWT token logic into a separate private method: +private static String extractJwtToken(HttpServletRequest request) {
+ try {
+ return CookieUtil.getJwtTokenFromCookie(request);
+ } catch (Exception e) {
+ logger.error("Error while getting jwtToken from Cookie" + e.getMessage());
+ return null;
+ }
+}
+
+private static void enrichHeadersWithTokenAndUserAgent(HttpHeaders headers, HttpServletRequest request) {
+ String jwtTokenFromCookie = extractJwtToken(request);
+
+ if (null != UserAgentContext.getUserAgent()) {
+ headers.add(HttpHeaders.USER_AGENT, UserAgentContext.getUserAgent());
+ }
+ if (null != jwtTokenFromCookie) {
+ headers.add(Constants.JWT_TOKEN, jwtTokenFromCookie);
+ } else if (null != request.getHeader(Constants.JWT_TOKEN)) {
+ headers.add(Constants.JWT_TOKEN, request.getHeader(Constants.JWT_TOKEN));
+ }
+}Then update both methods to use this shared logic.
π€ Prompt for AI Agents |
||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.