TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

24 点作者 lynndylanhurley将近 11 年前
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 条评论

afiedler将近 11 年前
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 未加载
lynndylanhurley将近 11 年前
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 未加载
evbots将近 11 年前
Finally someone is doing a token based auth system for rails APIs