Failing to set token in user model

Nelio Lucas 7 years ago

Hi, i seem to be having some issues trying to create a user with a token. However if i remove the token field im able to create the the user. the problem is that the token field will remain null.

Here is the error i get when i tried creating a user with the token field using Postman

Illegal token
 at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@b2257b0; line: 1, column: 84] (through reference chain: org.traccar.model.User["token"])

this is the request url : http://localhost:8082/api/users/

this is the request body

{"name":"Test That","password":"test","email":"test","administrator":true, "token":"dfsdf", "id":-1}
Anton Tananaev 7 years ago

It have to match some minimal security requirements:

            if (!token.matches("^[a-zA-Z0-9-]{16,}$")) {
                throw new IllegalArgumentException("Illegal token");
            }
Nelio Lucas 7 years ago

ahh alright! thanks! i got it to work now!

Antonio Junior 2 years ago

Greetings, is it possible to send a POST request to create a user with a token parameter? I didn't see this in the traccar API. @Nelio Lucas. Thanks!

Anton Tananaev 2 years ago

It's possible.

Antonio Junior 2 years ago

Perfect, thanks.

Antonio Junior 2 years ago

@Nelio Lucas
Would you help me
Unrecognized field "token" (class org.traccar.model.User)

{
	"email":"testex@testex",
	"name":"testex",
	"password":"123123",
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9xeyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQqNFvYpuwbF6YWbPyaNAGEPw9wbhiQSovvSrD89B8K7Ng"
}
Anton Tananaev 2 years ago

Why are you asking this on a 5 year old thread? Things changed since that time.

Antonio Junior 2 years ago

I didn't open another topic because as I found this one so as not to duplicate it, honestly I was so happy to be able to send a token in POST that I didn't notice the date of the topic, I need to open a new one or could I let you know if it is still possible and how I could correct it please.

Anton Tananaev 2 years ago

You cannot set the token. The API has been changed and this has been discussed several times. Please search.

Antonio Junior 2 years ago

I saw Anton, that's why I asked at the beginning if it was possible, unfortunately I just didn't pay attention to the date, my intention from the beginning was to generate the token for another user via the web application, I even managed to do it, but how is it necessary to create the session? The previous user is automatically logged out. Thanks!