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.

Show HN: Secure token authentication for Angular.js and Rails

24 pointsby lynndylanhurleyalmost 11 years ago
Angular module: https:&#x2F;&#x2F;github.com&#x2F;lynndylanhurley&#x2F;ng-token-auth<p>Rails gem: https:&#x2F;&#x2F;github.com&#x2F;lynndylanhurley&#x2F;devise_token_auth<p>I&#x27;ve been working hard to make this the most simple, flexible, and secure token auth system in existence. I believe that I&#x27;m close to succeeding. I&#x27;d love to hear your thoughts on what I can do to improve what I have so far.

3 comments

afiedleralmost 11 years ago
Oh man, I wish this was around about a year ago. I actually coded most of this for a client and it was extremely painful to get correct. We are using the Doorkeeper OAuth2 gem which uses slightly different tokens and has some different features, though.<p>Couple of things&#x2F;feature you might want to consider:<p>* You might want to track the expiration time of the tokens if the API provides it. If the token isn&#x27;t expired, potentially skip the verification step.<p>* Potentially you might want to add another HTTP interceptor that catches 401 (Unauthorized) responses. If a response returns a 401, you can prompt the user to re-authenticate and hold all HTTP requests until the user does. Then when there is a new token available, you can replay requests. This, coupled with saving the expiration time, can make page load times faster and still be robust.<p>* I&#x27;d make the HTTP interceptor that adds the Authorization header only add the header if the request URL is going to an API endpoint. The library user should be able to specify a function or regex that takes a URL string and returns true if the URL is an API url (and thus needs an Authorization header). Otherwise you&#x27;d include the token on unrelated requests to 3rd parties.<p>Nice job though, I&#x27;ll definitely check this out next time I need to do token auth on Angular.
评论 #7985737 未加载
lynndylanhurleyalmost 11 years ago
Some questions that I have:<p>Is the documentation clear?<p>Is there anything that I can do to further simplify anything?<p>Are the security measures too aggressive? Not aggressive enough?
评论 #7985983 未加载
评论 #7985847 未加载
evbotsalmost 11 years ago
Finally someone is doing a token based auth system for rails APIs