Peter Penzov
Peter Penzov

Reputation: 1588

Implement authentication endpoint with JWT

I wan to implement authentication endpoint for Angular Login page. I tried to implement this example.

But I have 2 questions which are not clear: 1. What is the endpoint to which I need to make a POST request with user and pass in order to get a token as response? Looking at the tutorial diagram it should be /users/login but I don's see this endpoint implemented: enter image description here

  1. I need to use custom SQL in order to get the user from the DB. Do I need to make a custom handler?

Upvotes: 0

Views: 121

Answers (1)

muasif80
muasif80

Reputation: 6006

  1. It is there under /users/signin in User Controller. The method name is still login. The path /users is mapped to the controller and the /signin is mapped to the method

  2. Yes. You will have to provide some custom implementation

    1. In loadByUsername method inside MyUserDetails you can only pass username as parameter.
    2. If you instead want to use some more filters then implement a different service and implement a method in it that returns instance UserDetails subclass which is then used by the JwtTokenProvider getAuthentication() method
    3. Put that in place of @Autowired MyUserDetails in JwtTokenProvider class
    4. Implement a method there that returns UserDetails with all the needed data that is then used in JwtTokenProvider -> getAuthentication() method

Upvotes: 1

Related Questions