2021年3月27日星期六

How to identify the full response body of refresh token API?

These are authentication & refresh token API developed for a mobile app. Can anyone help to identify the response body for the refresh token API based on this codes? I am somehow confused of the full response body. I believe the final response would be:

{  "success":true,  "message":"Refresh Token generated"  }  

But what is the full response before that?

@ApiOperation(value = "Authenticate", tags = {})      @ApiResponses(value = {              @ApiResponse(code = HttpServletResponse.SC_OK, message = "The response body contains a boolean value and a message.", response = ResponseBase.class),              @ApiResponse(code = HttpServletResponse.SC_BAD_REQUEST, message = "Bad Request.", response = ResponseBase.class),              @ApiResponse(code = HttpServletResponse.SC_UNAUTHORIZED, message = "Login failed.", response = ResponseBase.class),              @ApiResponse(code = HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message = "Make sure specify 'application/json' as the media type.", response = ResponseBase.class),              @ApiResponse(code = HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message = "Internal Server Error", response = ResponseBase.class)      })      @RequestMapping(value = Constants.REST_API_AUTH, method = RequestMethod.POST)      public ResponseEntity<Object> createAuthenticationToken(@RequestBody @Valid AuthenticationRequest request) throws Exception {            String msg = null;            try {              authenticationManager.authenticate(                      new UsernamePasswordAuthenticationToken(request.getUsername(), request.getUsername())              );          } catch (BadCredentialsException e) {              msg = "Incorrect username or password";          } catch (AccountStatusException e) {              msg = e.getMessage();          }          if (null != msg) {              msg = "Login failed: " + msg;              String detail = request.toString();              log.info(msg);              throw new RestApiException(HttpStatus.UNAUTHORIZED, false, msg, detail);          }            if (smsUtil.isSGNumber(request.getUsername())) {              String result = otpService.checkOtp(request.getUsername(), request.getPassword());              msg = "Login failed: OTP " + result;              if (Constants.OTP_STATUS_EXP.equals(result) || Constants.OTP_STATUS_MIS.equals(result)) {                  throw new RestApiException(HttpStatus.UNAUTHORIZED, false, msg, msg);              }          }            final UserDetail userDetail = new UserDetail(request.getUsername(), "");            final String token = jwtTokenUtil.generateToken(userDetail);            ResponseBase body = new ResponseBase();          msg = "Login successful";          log.info("{} : {}", msg, request);          body.setSuccess(true);          body.setMessage(msg);          return httpUtil.createResponseEntityJson(HttpStatus.OK, httpUtil.createSecTokenHeader(token), body);      }          @GetMapping(value = Constants.REST_API_REFRESH_TOKEN)      public ResponseEntity<Object> getRefreshToken(@RequestHeader(Constants.HTTP_AUTH_HEADER) String authHeader, HttpServletRequest request) {          log.info("Generate refresh token");          String token = httpUtil.extractSecurityToken(authHeader);          ResponseBase body = new ResponseBase();          body.setSuccess(true);          body.setMessage("Refresh Token generated");            String refreshToken;          DefaultClaims claims = (io.jsonwebtoken.impl.DefaultClaims) request.getAttribute("claims");          if(null == claims) {              refreshToken = jwtTokenUtil.renewToken(token);          } else {              refreshToken = jwtTokenUtil.renewToken(claims);          }          return httpUtil.createResponseEntityJson(HttpStatus.OK, httpUtil.createSecTokenHeader(refreshToken), body);      }  }  
https://stackoverflow.com/questions/66838058/how-to-identify-the-full-response-body-of-refresh-token-api March 28, 2021 at 11:08AM

没有评论:

发表评论