Почтальон: «Введенные данные не являются допустимой строкой в ​​кодировке Base64».JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Почтальон: «Введенные данные не являются допустимой строкой в ​​кодировке Base64».

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»