visit
Two of the most important of these authentication standards are OAuth and JWT (JSON Web Tokens).
When you implement "Sign in with Google" or "Sign in with Github", you are using the OAuth 2.0 protocol!
It’s the accepted industry standard. This means that most authentication services will understand and use OAuth 2.0.
There are many plug-and-play OAuth options. Including services like "Sign in with Google" and "Sign in with Facebook" that are already set up to be consumed within your application.
OAuth has well-tested client libraries in almost all languages and web frameworks. This means that your language of choice can be used with OAuth
It allows for the decoupling of code. Your client application code is not affected by the authentication code.
OAuth is very secure and battle-tested. Due to its widespread nature, you can rest assured that all security edge cases have been thought about by industry experts.
OAuth can be complicated to understand if you are unfamiliar. There are several different OAuth flows and deciding which is right for you can be a challenge. Sometimes, you may even need to use multiple flows.
It has lower end-user privacy. The auth server knows all the sites that the end-user has logged in to. For example, when a site uses Sign in with Google, Google would be able to keep track of when that site’s users are signing in or are active.
It’s overkill in certain situations. If you are building a simple web app that has one frontend and backend, then you don’t need the OAuth protocol. However, a lot of online tutorials and ready-made auth solutions force you to implement this.
No session management solution. Once the user is authenticated, the auth server simply returns a JWT which can be consumed by your application (as well will see later). However, after that step, the OAuth protocol doesn’t provide any support for specifying how to maintain the authenticated session between your app’s frontend and backend - this is totally up to the developer.
They are self-contained. The JWT can contain the user’s details. So you don’t need to query a database/auth server for that information on each request.
They offer strong security guarantees. JWTs are digitally signed which safeguards them from being modified by the client or an attacker.
JWTs are stored only on the client. You generate JWTs on the server and send them to the client. The client then submits the JWT with every request. This saves database space.
They are efficient and quick to verify. This is because JWTs don’t require a database lookup.
You can’t revoke them without putting in a lot of extra engineering effort. This is because there is no db call when verifying them. In order to implement immediate revocation, you would need to which can be time-consuming.
It’s easy to create security bottlenecks while keeping one secret safe. If the signing key is compromised, the attacker can use that to create their own valid JWTs. This would allow them to spoof the identity of any user and application.
{
"iss": "//accounts.google.com",
"azp": "00.apps.googleusercontent.com",
"aud": "00.apps.googleusercontent.com",
"sub": "0062367",
"at_hash": "HK6E_P6Dh8Y93mRNtsDB1Q",
"email": "[email protected]",
"email_verified": "true",
"iat": 1353601026,
"exp": 1353604926,
"nonce": "0-2490358",
"hd": "example.com",
}
is: The issuer of the token (in this case Google)
azp and aud: Client IDs issued by Google for your application. This way, Google knows which website is trying to use its sign-in service, and the website knows that the JWT was issued specifically for them.
sub: The end user’s Google user ID
at_hash: The hash of the access token. The OAuth access token is different from the JWT in the sense that it’s an opaque token. The access token’s purpose is so that the client application can query Google to ask for more information about the signed-in user.
email: The end user’s email ID
email_verified: Whether or not the user has verified their email.
iat: The time (in milliseconds since epoch) the JWT was created
exp: The time (in milliseconds since epoch) the JWT was created
nonce: Can be used by the client application to prevent replay attacks.
hd: The hosted G Suite domain of the user
Written by the Folks at — hope you enjoyed! We are always available on our server. Join us if you have any questions or need any help.