Почтальон: «Введенные данные не являются допустимой строкой в кодировке Base64». ⇐ JAVA
Почтальон: «Введенные данные не являются допустимой строкой в кодировке Base64».
For a school project I'm trying to use a JWT token as authentication, when the JWT token contains the role "coach", it means that the user is authorized to do something.
I wrote the method that creates a String, and one that should decode it, but when I put the string that I get into Postman, I get a 500 internal server error because according to Postman, it's not a valid base64-encoded string. In jwt.io, it decodes without any problems...
The code I wrote is as follows:
Algorithm algorithm = Algorithm.HMAC256("wisebite"); public String login() { String jwtToken = JWT.create() .withIssuer("wisebite") .withSubject("wisebitedetails") .withClaim("role", "coach") .withIssuedAt(new Date()) .withExpiresAt(new Date(System.currentTimeMillis() + 5000L)) .withJWTId(UUID.randomUUID() .toString()) .withNotBefore(new Date(System.currentTimeMillis() + 1000L)) .sign(algorithm); return jwtToken; } public boolean hasAcces (String jwtToken) { JWTVerifier jwtVerifier = JWT.require(algorithm).withIssuer("wisebite").build(); DecodedJWT decodedJWT = jwtVerifier.verify(jwtToken); if (decodedJWT.getClaim("role").equals("coach")) { return true; } else { return false; } } Yes, I know, this is not the way to log in since nothing is checked, but I want to see if this code works first, so when i navigate to http://localhost:8080/coach/login in Postman I receive a jwtToken:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ3aXNlYml0ZWRldGFpbHMiLCJyb2xlIjoiY29hY2giLCJuYmYiOjE3MDk3MTM3ODQsImlzcyI6Indpc2ViaXRlIiwiZXhwIjoxNzA5NzEzNzg4LCJpYXQiOjE3MDk3MTM3ODMsImp0aSI6ImY4Zjc3NzkxLTlmYjgtNDNlNi1iNTFjLTRlOTk1ZDQ2NGZmYyJ9.8sitspmE0N_Ai47qrIQmrp4szVc4mwDANlpN5L0jJbg When I go to http://localhost:8080/coach/overview/user and put this jwtToken in the body, I get the error saying it's not base64 encoded...
Below is the @Getmapping
@GetMapping("/overview/{username}") private ResponseEntity getPlanByClient(@PathVariable String username, @RequestBody String jwtToken) { if (authenticationService.hasAcces(jwtToken)) { I'm using the Auth0 library version 4.2.1 I think that's about all the information I have available, what am I doing wrong?
Источник: https://stackoverflow.com/questions/781 ... ded-string
For a school project I'm trying to use a JWT token as authentication, when the JWT token contains the role "coach", it means that the user is authorized to do something.
I wrote the method that creates a String, and one that should decode it, but when I put the string that I get into Postman, I get a 500 internal server error because according to Postman, it's not a valid base64-encoded string. In jwt.io, it decodes without any problems...
The code I wrote is as follows:
Algorithm algorithm = Algorithm.HMAC256("wisebite"); public String login() { String jwtToken = JWT.create() .withIssuer("wisebite") .withSubject("wisebitedetails") .withClaim("role", "coach") .withIssuedAt(new Date()) .withExpiresAt(new Date(System.currentTimeMillis() + 5000L)) .withJWTId(UUID.randomUUID() .toString()) .withNotBefore(new Date(System.currentTimeMillis() + 1000L)) .sign(algorithm); return jwtToken; } public boolean hasAcces (String jwtToken) { JWTVerifier jwtVerifier = JWT.require(algorithm).withIssuer("wisebite").build(); DecodedJWT decodedJWT = jwtVerifier.verify(jwtToken); if (decodedJWT.getClaim("role").equals("coach")) { return true; } else { return false; } } Yes, I know, this is not the way to log in since nothing is checked, but I want to see if this code works first, so when i navigate to http://localhost:8080/coach/login in Postman I receive a jwtToken:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ3aXNlYml0ZWRldGFpbHMiLCJyb2xlIjoiY29hY2giLCJuYmYiOjE3MDk3MTM3ODQsImlzcyI6Indpc2ViaXRlIiwiZXhwIjoxNzA5NzEzNzg4LCJpYXQiOjE3MDk3MTM3ODMsImp0aSI6ImY4Zjc3NzkxLTlmYjgtNDNlNi1iNTFjLTRlOTk1ZDQ2NGZmYyJ9.8sitspmE0N_Ai47qrIQmrp4szVc4mwDANlpN5L0jJbg When I go to http://localhost:8080/coach/overview/user and put this jwtToken in the body, I get the error saying it's not base64 encoded...
Below is the @Getmapping
@GetMapping("/overview/{username}") private ResponseEntity getPlanByClient(@PathVariable String username, @RequestBody String jwtToken) { if (authenticationService.hasAcces(jwtToken)) { I'm using the Auth0 library version 4.2.1 I think that's about all the information I have available, what am I doing wrong?
Источник: https://stackoverflow.com/questions/781 ... ded-string
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Пытаюсь заполнить данные всплывающего окна и применить введенные данные.
Anonymous » » в форуме Python - 0 Ответы
- 35 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Пытаюсь заполнить данные всплывающего окна и применить введенные данные.
Anonymous » » в форуме Python - 0 Ответы
- 29 Просмотры
-
Последнее сообщение Anonymous
-