forked from murraco/spring-boot-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
|
||
![](https://img.shields.io/badge/java_8-✓-blue.svg) | ||
![](https://img.shields.io/badge/spring_boot-✓-blue.svg) | ||
![](https://img.shields.io/badge/swagger_2-✓-blue.svg) | ||
![](https://img.shields.io/badge/mysql-✓-blue.svg) | ||
![](https://img.shields.io/badge/jwt-✓-blue.svg) | ||
![](https://img.shields.io/badge/swagger_2-✓-blue.svg) | ||
|
||
You can find a related post for this repository [here](https://medium.com/@xoor/jwt-authentication-service-44658409e12c). | ||
|
||
|
@@ -318,24 +319,70 @@ http.apply(new JwtTokenFilterConfigurer(jwtTokenProvider)); | |
|
||
# How to use this code? | ||
|
||
1. Make sure you have Java 1.8 and maven installed | ||
1. Make sure you have [Java 8](https://www.java.com/download/) and [Maven](https://maven.apache.org) installed | ||
|
||
``` | ||
mvn install | ||
``` | ||
2. Fork this repository and clone it | ||
|
||
``` | ||
$ git clone https://github.com/<your-user>/spring-boot-jwt | ||
``` | ||
3. Navigate into the folder | ||
2. Run the project | ||
``` | ||
$ cd spring-boot-jwt | ||
``` | ||
``` | ||
mvn spring-boot:run | ||
``` | ||
4. Install dependencies | ||
3. Navigate to `http://localhost:8000/swagger-ui.html` in your browser to check everything is working correctly. You can change the default port in the following `application.yml` file. | ||
``` | ||
$ mvn install | ||
``` | ||
5. Run the project | ||
``` | ||
$ mvn spring-boot:run | ||
``` | ||
6. Navigate to `http://localhost:8000/swagger-ui.html` in your browser to check everything is working correctly. You can change the default port in the following `application.yml` file | ||
```yml | ||
server: | ||
port: 8090 | ||
``` | ||
|
||
7. Make a GET request to `/users/me` to check you're not authenticated. You should receive a response with a `403` with an `Access Denied` message since you haven't set your valid JWT token yet | ||
|
||
``` | ||
$ curl -X GET http://localhost:8080/users/me | ||
``` | ||
|
||
8. Make a POST request to `/users/signin` with the default admin user we programatically created to get a valid JWT token | ||
|
||
``` | ||
$ curl -X POST 'http://localhost:8080/users/signin?username=admin&password=admin' | ||
``` | ||
|
||
9. Add the JWT token as a Header parameter and make the initial GET request to `/users/me` again | ||
|
||
``` | ||
$ curl -X GET http://localhost:8080/users/me -H 'Authorization: Bearer <JWT_TOKEN>' | ||
``` | ||
|
||
10. And that's it, congrats! You should get a similar response to this one, meaning that you're now authenticated | ||
|
||
```javascript | ||
{ | ||
"id": 1, | ||
"username": "admin", | ||
"email": "[email protected]", | ||
"roles": [ | ||
"ROLE_ADMIN" | ||
] | ||
} | ||
``` | ||
|
||
``` | ||
server: | ||
port: 8090 | ||
``` | ||
# Contribution | ||
|
||
- Report issues | ||
|