An open API service indexing awesome lists of open source software.

https://github.com/shaikrasheed99/springboot-security-jwt-authentication

JWT Authentication in Springboot.
https://github.com/shaikrasheed99/springboot-security-jwt-authentication

jwt jwt-authentication jwt-authorization spring-boot spring-jwt-authentication spring-security spring-security-jwt spring-security-jwt-spring-boot

Last synced: about 1 month ago
JSON representation

JWT Authentication in Springboot.

Awesome Lists containing this project

README

          

# Spring Security JWT Authentication

## Gradle based spring boot application which provide below APIs of the users using test driven development.

## APIs of the Application

- Signup
- Login
- Get all users
- Get user by username

## APIs

### Signup - `/auth/signup`

* `NOTE` - this API can be accessed by everyone.

* Request

```
curl --location --request POST 'http://localhost:8080/auth/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "test_username",
"password": "test_password",
"role": "ROLE_test",
"firstname": "test_firstname",
"lastname": "test_lastname"
}'
```

* Response

```
{
"status": "success",
"code": "CREATED",
"message": "user has created successfully",
"data": {
"token": "JWT_TOKEN"
}
}
```

### Login - `/auth/login`

* Request

```
curl --location --request POST 'http://localhost:8080/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "test_username",
"password": "test_password"
}'
```

* Response

```
{
"status": "success",
"code": "OK",
"message": "user has logged in successfully",
"data": {
"token": "JWT_TOKEN"
}
}
```

### Get all users - `/users`

* `NOTE` - this API can be accessed by authenticated users who are having admin role.

* Request

```
curl --location --request GET 'http://localhost:8080/users' \
--header 'Authorization: Bearer JWT_TOKEN' \
```

* Response

```
{
"status": "success",
"code": "OK",
"message": "fetched users details successfully!!",
"data": {
"users": [
{
"username": "test_username",
"password": "test_password",
"firstname": "test_firstname",
"lastname": "test_lastname",
"role": "ROLE_test"
}
]
}
}
```

### Get User by username - `/users/{username}`

* `NOTE` - this API can be accessed by authenticated users who are having admin and user roles.

* Request

```
curl --location --request GET 'http://localhost:8080/users/test_username' \
--header 'Authorization: Bearer JWT_TOKEN' \
```

* Response

```
{
"status": "success",
"code": "OK",
"message": "fetched user details successfully!!",
"data": {
"user": {
"username": "test_username",
"password": "test_password",
"firstname": "test_firstname",
"lastname": "test_lastname",
"role": "ROLE_test"
}
}
}
```