TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Authentication Techniques for APIs

257 pointsby Sujanabout 8 years ago

13 comments

cleverfooabout 8 years ago
Not impressed, particularly with the basic-auth description. Basic auth is purely a well understood vehicle for sending a tuple (aka the credentials) for authenticating a HTTP request, most of the concerns highlighted are with regards to how the credentials are acquired and potentially reused across requests - that has nothing to do with the HTTP protocol. For example, my API product scanii.com has used basic auth for 7+ years and I firmly believe it strikes the right balance between security and easy of use. Besides fairly complex key/secret tuples for server side usage, we also provide one-time auth tokens for when you want to make API calls directly from a web browser (or another insecure device).
评论 #14300737 未加载
deathanatosabout 8 years ago
I feel that this table leads readers into thinking that the top axis is a set of things you need to choose between, but many of them are orthogonal. JWTs, for example, can be used as a particular (standardized) &quot;stateless session cookie&quot; if you store them as a cookie. They do not, contrary to what the table says, need to be stored in local&#x2F;session storage, though that is an option. Similarly with &quot;Random Token&quot; and &quot;Stateful Session Cookie&quot;.<p>OAuth, similarly, is orthogonal to the rest of the table. You can easily use JWT as your token format in OAuth.<p>The key decisions you have to make are something like,<p>* Do I have any sort of &quot;authentication token&quot;, or does the client simply auth each request?<p>If you go w&#x2F; authing each request, you get things like HTTP Basic Auth, or AWS&#x27;s style.<p>If you go with some sort of token, then you get <i>both</i> of the following questions:<p>* If token, do you store the token in a cookie, or local&#x2F;sessionStorage? (The former is vulnerable to CSRF, the latter can be read by JS in an XSS.)<p>* If token, what kind of token? A reference to a row in a DB, or do you just give the client a signed and possibly encrypted blob detailing the authentication?<p>If you go w&#x2F; a signed and possibly authenticated blob, then JWT provides a standard format for representing that data and many of the concerns around authentication tokens, such as expiration.<p>I&#x27;m probably over-simplifying a bit. The table just doesn&#x27;t — for me — do a good job of showing the various choices along the spectrum, and what consequences arise from which choices. (Aside from also conflating JWTs with where you store an auth token, and Oauth with auth tokens)<p>(&quot;Stateless Session Cookie&quot; is a bit of an oxymoron.)
评论 #14305594 未加载
sk5tabout 8 years ago
Who is the author? It&#x27;s just a bare Google Doc AFAICT.<p>Some quick notes: random tokens do rely, broadly speaking, on cryptography, as the token must be generated by a cryptographically strong (P)RNG.<p>Signing and encryption are conceptually different ideas, don&#x27;t mix them as in the description of the stateless session cookie. There&#x27;s a great old Matasano blog post in the style of a play about this...<p>A more complete consideration of authn techniques would include mutual certificate (&quot;SSL&quot;) authn, as well as signed-request approaches not using a shared secret.
评论 #14300195 未加载
评论 #14299850 未加载
btillyabout 8 years ago
Every time I see &quot;API&quot; and &quot;authentication&quot; I go look to see whether they have incorporated the best practice of always be willing to accept two different authentication credentials&#x2F;passwords&#x2F;etc. So that upgrades can happen where first one side will accept a new password, then the other side switches what it sent, then the old password is discontinued.<p>Rather than the common &quot;big bang&quot; upgrade where everything has to update at once. (A process which is so scary that in fact it turns into passwords NEVER getting updated.)<p>Yeah, sadly this idea is never mentioned. :-(
ezekgabout 8 years ago
I seriously don&#x27;t understand the hype around JWT. They&#x27;re useless to me since they can&#x27;t be revoked. It&#x27;s so much easier to just use a secure random token with an expiry. I could understand JWT at-scale to avoid hits to the DB, but none of us are likely at that scale.
评论 #14301301 未加载
评论 #14301780 未加载
nwhattabout 8 years ago
Calling the last column &quot;OAuth&quot; over-simplifies quite a bit. Specifically, there are ways to do OAuth like client credentials that don&#x27;t involve 3 parties. OAuth provides a standard way of solving authentication, and it makes life easier for developers. Saying it&#x27;s &quot;overkill&quot; might turn people away from a solution that could help them get and retain API customers. More about client credentials here: <a href="https:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;draft-ietf-oauth-v2-31#section-4.4" rel="nofollow">https:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;draft-ietf-oauth-v2-31#section-4...</a>
throwasehasdwiabout 8 years ago
JWT docs aren&#x27;t accurate. Also why not just store JWT in the cookie? It&#x27;s pretty trivial to use JWT in a cookie and do a sliding refresh on server side when its close to expiring. You can use JWT this way with zero code on the client.<p>Same with the &quot;Random Token&quot;. You can easily just shove a secure random ID in a session cookie and use it. Doesn&#x27;t pretty much every framework support this?<p>This docs is... not accurate for most of these.
评论 #14300216 未加载
评论 #14300049 未加载
评论 #14300825 未加载
bkmartinabout 8 years ago
What about JWT with Refresh Tokens? How does this fit in the list and does it help alleviate any concerns covered by the other methods?
davidpelayoabout 8 years ago
Keeping this information, which I think is very useful, on a github repo here: <a href="https:&#x2F;&#x2F;github.com&#x2F;teamsecure&#x2F;authentication" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;teamsecure&#x2F;authentication</a>. Submit PR or create issue and collaborate if you feel like to do it :)
newsat13about 8 years ago
Question about this from your blog:<p>&gt; Does your web framework protect against CSRF? If no, or if you don’t know what CSRF is – prefer token based authentication.<p>Can you elaborate on this? If I implement CORS and also make sure my API is well-designed (for example, GET requests are truly idempotent and do not mutate anything), am I not protected from CSRF?<p>Thanks!
评论 #14306469 未加载
评论 #14306472 未加载
ausjkeabout 8 years ago
After reading through this it seems no clear winner, most of them are &quot;painful&quot; in implementation?
评论 #14300241 未加载
linkedlist007about 8 years ago
Is there a book to learn more indepth about all these?
评论 #14301197 未加载
评论 #14300406 未加载
评论 #14303655 未加载
评论 #14299992 未加载
评论 #14299814 未加载
shussonabout 8 years ago
I&#x27;d add a section&#x2F;row on `browser vulnerability: XSS`.