REST API for authenticating users.
INSERT INTO roles(name) VALUES('ROLE_ADMIN');
INSERT INTO roles(name) VALUES('ROLE_MODERATOR');
INSERT INTO roles(name) VALUES('ROLE_USER');
Below are the REST APIs for the example app.
POST /api/signup
curl --location --request POST 'http://localhost:8080/api/signup' \--header 'Content-Type: application/json' \--data-raw '{"username":"ckb","email":"[email protected]","password":"tyugbjhn"}'
{
"success": true,
"message": "User registered successfully"
}
- Email already in use
{
"success": false,
"message": "Email is already in use"
}
- Username is already taken
{
"success": false,
"message": "Username is already taken"
}
POST /api/signin
curl --location --request POST 'http://localhost:8080/api/signin' \--header 'Content-Type: application/json' \--data-raw '{"usernameOrEmail":"ckb","password":"qwerty"}'
{
"accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJja2IiLCJpYXQiOjE2NzAyNDc1OTksImV4cCI6MTY3MDI0NzY4NX0.CwuhFGhu0S15q5xpXWHfFqj836fXh2W3z1r6RpmcPlEswe50XcfXVg9iLW6F_QDRnnyzxFNJdAoMnWKDmTrq7g",
"tokenType": "Bearer",
"expiresIn": 86400
}
POST /api/[email protected]
curl --location --request POST 'http://localhost:8080/api/[email protected]' \--data-raw ''
Reset token is sent to the user via provided email if it exists.
{
"success": true,
"message": "We have sent a password reset token to [email protected]"
}
- No account with the Email Address
{
"success": false,
"message": "There is no account with an email address"
}
POST /api/reset?token=c52d4ed8-f4a2-41de-90ca-f97bc4a56e37
curl --location --request POST 'http://localhost:8080/api/reset?token=c52d4ed8-f4a2-41de-90ca-f97bc4a56e37' \--header 'Content-Type: application/json' \--data-raw '{"password":"qwerty"}'
{
"success": true,
"message": "Your password has been successfully reset."
}
- Invalid token
{
"success": false,
"message": "The password reset link is invalid."
}
POST /api/users/in/{username}
curl --location --request GET 'http://localhost:8080/api/users/in/{username}'
{
"success": true,
"message": "User with username available",
"data": {
"id": 1,
"email": "[email protected]",
"username": "ckb",
"roles": [
{
"id": 1,
"name": "ROLE_USER"
}
]
}
}
- No user with username provided
{
"success": false,
"message": "No account with username provided"
}