bezkoder / spring-boot-spring-security-jwt-authentication

Spring Boot + Security: Token Based Authentication example with JWT, Authorization, Spring Data & MySQL
1.34k stars 828 forks source link

Signup posts generates 401 #21

Open thomaschristensen opened 1 year ago

thomaschristensen commented 1 year ago

When trying to create users following the example in the docs I get 401 on posting to /api/auth/signup

thomaschristensen commented 1 year ago

Appears to be when username is shorter than 3 letters and this error does not end up in the returned message

tienbku commented 1 year ago

Hi, you can validate the request body. Kindly read following tutorial: https://www.bezkoder.com/spring-boot-validate-request-body/

bsuriyakuts commented 1 year ago

Getting 401 issue while calling singup api. any solutions can be suggested?

phiau commented 1 year ago

Getting 401 issue while calling singup api. any solutions can be suggested?

curl --location 'localhost:8080/api/auth/signup' \ --header 'Content-Type: application/json' \ --header 'Cookie: JSESSIONID=89CC086CF0D4CF7D8A3E542AFA8CDF54' \ --data-raw '{ "username":"phiauphiau", "email":"phiau@phiau.com", "password":"phiauphiau", "role":[] }'

Above curl request work fine. Below getting the 401 as you.

curl --location --request POST 'localhost:8080/api/auth/signup?username=phiauphiau&email=phiau%40phiau.com&password=phiauphiau&role=ROLE_USER' \ --header 'Cookie: JSESSIONID=89CC086CF0D4CF7D8A3E542AFA8CDF54'

lthchinchin commented 8 months ago

Addon ValidationExceptionHandler Class. See in the article: https://www.bezkoder.com/spring-boot-validate-request-body/

VitusJoy commented 6 months ago

@thomaschristensen got the solution?

thomaschristensen commented 6 months ago

No, but I haven't tried with newer versions

VitusJoy commented 6 months ago

No, but I haven't tried with newer versions

on java java -version java version "17.0.1" 2021-10-19 LTS Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

Screenshot 2024-05-07 at 4 30 24 PM

nothing on console

***property spring.datasource.url=jdbc:mysql://localhost:3306/DB_1?useSSL=false spring.datasource.username=root spring.datasource.password=PASSWORD spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect spring.jpa.hibernate.ddl-auto=update bezkoder.app.jwtSecret= ======================BezKoder=Spring=========================== bezkoder.app.jwtExpirationMs=86400000