Web Service JAX RS JWT JJWT or Auth0

0

I want to use a library to implement jwt . I have tried some but I have problems with jersey that does not recognize the bookstores. I followed some tips in Stack, but I do not understand how to handle the filters with jersey and others.

Can not you simply create a token and add it to the answer header?

@POST
@Produces("application/json")
@Consumes("application/x-www-form-urlencoded")
public Response authenticateUser(@FormParam("username") String username, 
                               @FormParam("password") String password) {
try {
// Authenticate the user using the credentials provided
// authenticate(username, password);
// Issue a token for the user
String compactJws = Jwts.builder().setSubject(username).signWith(SignatureAlgorithm.HS512, "pepe").compact();

   // Return the token on the response
   return Response.ok(compactJws).build();

    } catch (Exception e) {
        return Response.status(Response.Status.UNAUTHORIZED).build();
    }      
}

In the piece of code that I copied I used jjwt, that gives me an error of classnotfound but the libraries are imported without problems ..

with Auth0.jwt I had no problems and creates the token and sends it in the answer. Assuming that is ok, should I check in each method if the token is valid? I think the idea of filters is not to do this, but I can not understand it.

These are the two queries I was following.

Jersey

authorization

    
asked by Matias Blanco 28.07.2016 в 00:17
source

0 answers