Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Web Token (JWT) : Authorization vs Authentication

Tags:

JWT terminology has been bothering me for a few reasons. Is JWT suitable for Authorization or is it only for Authentication?

Correct me if I'm wrong but I have always read Authorization as being the act of allowing someone access to a resource yet JWT doesn't seem to have any implementation that actually allows access to users to a given resource. All JWT implementations talk about is providing a user a token. This token is then passed with every call to a back-end service endpoint where it is checked for validity and if valid access is granted. So we can use JWT for Authentication of any user but how can we restrict the access to particular valid users ?

How can we use JWT for restricting a few users depending on roles they have? Do JWT provide any type of Authorization details as well or does it just provide us Authentication ?

Thanks in advance for your help and reading my doubt patiently.

like image 847
Rohan Kadu Avatar asked Jan 22 '18 16:01

Rohan Kadu


People also ask

Is JWT token for authentication or authorization?

JWT is commonly used for authorization. JWTs can be signed using a secret or a public/private key pair. Once a user is logged in, each subsequent request will require the JWT, allowing the user to access routes, services, and resources that are permitted with that token.

What are the main differences between JWT and OAuth authentication?

JWT is a JSON based security token forAPI AuthenticationJWT is just serialised, not encrypted. OAuth is not an API or a service: it's an open standard for authorization . OAuth is a standard set of steps for obtaining a token. There are 5 different flow patterns.

Should I use JWT for authentication?

Bottom line. Although JWT does eliminate the database lookup, it introduces security issues and other complexities while doing so. Security is binary—either it's secure or it's not. Thus making it dangerous to use JWT for user sessions.

What is JWT authentication token?

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed.


1 Answers

Authorization with JWT can be achieved using the token specific claims.

As many other user information packaged as claims in the Json Web Token the specific permissions can be pre-filled in the token and can be intercepted later on by an authorization service.

Typically the authorization would be permission based where permissions are used to restrict access to an api endpoint (may also be used to grant users access to views on the frontend apps).

Here down a sample JWT token having a permission element:

{   "UserInfo": {     "id": "#{USER_ID}",     "roles": {       "#{ROLE_NAME}": "#{ROLE_ID}"     },     "permissions": {       "#{PERMISSION_NAME}": "#{PERMISSION_ID}",     }   },   "exp": 1488888888 } 
like image 131
tmarwen Avatar answered Oct 20 '22 23:10

tmarwen