Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
murraco committed May 29, 2020
1 parent d9188f6 commit 6957a6d
Showing 1 changed file with 61 additions and 14 deletions.
75 changes: 61 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6957a6d

Please sign in to comment.