Reputation: 497
A bit of a conceptual question: I am designing a private RESTful API that will be used by iOS and Android apps.
I am using JWT.
I have an api_users
table that allows access to the the API itself.
I also have a users
table for individual user login using the apps (i.e. an individual's e-mail and password).
So here's where I'm confused:
api_users
table and have a single authentication endpoint for users
, orapi_users
' and the users
' credentials for a valid JWT to be returned; orapi_users
and another for the regular users
).If I take the third route, in keeping with RESTful (stateless) design, would I need a second JWT to keep track of what user
is requesting my API?
Thank you all!
Upvotes: 1
Views: 1397
Reputation: 53533
A RESTful API shouldn't have a login process, that requires maintaining state. You'll authenticate by providing a valid JWT packet with each request, and in order to create the packet, you'll need a token and some sort of unique account identifier. You will not need any password to create the JWT packet.
Regarding getting a token, you have two options:
In either case, you'll need a table for users and another table for tokens.
Upvotes: 0
Reputation: 1195
You should not have two tables that represent two different types of users (e.g. API users / app users). One table is sufficient. In terms of keeping track of what user is requesting your API your logs should be sufficient unless you need to store and present additional metrics on the front-end or you wish to limit access (throttling / one request per user at a time) and your framework does not manage this. When your users authenticate with your app they will now be issued with a JWT token that can be used to make API calls.
Upvotes: 2