raphaelDL / spring-webflux-security-jwt

A JWT authorization and authentication implementation with Spring Reactive Webflux, Spring Boot 2 and Spring Security 5
301 stars 87 forks source link

How to use this application #4

Open dhavalmshah opened 6 years ago

dhavalmshah commented 6 years ago

Sorry I am new to this whole Spring Security scenario, and also to reactive programming. I am trying to run this application, and I am not sure how I can login to this application and generate the JWT Token for furthur requests to the resource server

oskar-szwajkowski commented 6 years ago

In the SecuredRestApplication.java file, you can see spring security chain configuration.

In this config you can see that both "/" and "/login" endpoints are behind AuthenticationWebFilter, which in this case has UserDetailsRepository inside containing single user, with password user.

After specifying those credentials in, for example curl request as -u parameter ( curl -u username:password -v http://example.com/login )

You should be able to see token coming back after succesful authentication.

Then to proceed with making request, copy this token into Authentication HTTP header, and use it for other endpoints, which will validate this token through JWTAuthorizationWebFilter.

heesuk-ahn commented 5 years ago

@dhavalmshah hello, I also saw this example code and implemented jwt extract.

If you are having difficulty, do you check my example?

https://github.com/heesuk-ahn/search-book-webflux/blob/master/backend/src/main/java/com/project/backend/user/controller/UserController.java

this code is jwt extract patial code example.

` private final Mono context = ReactiveSecurityContextHolder.getContext();

private Mono extractUserSeqIdFromJwtToken(Mono context) { return context.filter(c -> Objects.nonNull(c.getAuthentication())) .map(s -> s.getAuthentication().getPrincipal()) .cast(Long.class); }`