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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: How are you authenticating rest service clients

14 点作者 devb0x超过 11 年前
I&#x27;ve been playing with asp.net webapi and basic auth header (with user:pass in base 64).<p>If you have a angular or knockout front end, are you storing the login details in a cookie and passing in the header, or via a token? Where are you storing that token?<p>I am new to this sort of api &#x2F; javascript front end and want to deal with security according to best practice.<p>What do you recommend?

3 条评论

tptacek超过 11 年前
Don&#x27;t use usernames and passwords as API authentication. Generate a random 128 bit token for each user (RNGCryptoServiceProvider, GetBytes on a 16-byte array) and pass that as a header (or as Authorization). Make sure your API endpoints require HTTPS.
评论 #6858572 未加载
评论 #6844987 未加载
评论 #6848641 未加载
jo_超过 11 年前
Speaking purely from the backend, our login function takes the IP address of the requester, the login name, and password, then checks the password against the database. If the password matches up, the current date and time, the current IP, the current time, the session expiration date, and a buttload of details about the host machine are hashed together and encrypted with the system&#x27;s public key before being sent back as a token.<p>It&#x27;s up to the client to store the token however it likes, but our reference implementation stores it as a cookie on the local machine.<p>If a new request comes from an IP address which doesn&#x27;t match the encrypted token, or if there are system details in the encrypted token which don&#x27;t match up with the one on file (we restrict sessions to single instances), then the request is rejected.
评论 #6842422 未加载
junto超过 11 年前
We use ServiceStack with .NET and love it.<p>ServiceStack uses a HTTP cookie and supports a variety of authentication options out of the box, including basic auth.<p><a href="https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ServiceStack&#x2F;ServiceStack&#x2F;wiki&#x2F;Authentica...</a><p>We also use the easy hooks that ServiceStack offers to validate API developer &#x2F; app tokens as well.<p>Social Bootstrap API is a backbone example:<p><a href="https://github.com/ServiceStack/SocialBootstrapApi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ServiceStack&#x2F;SocialBootstrapApi</a><p><a href="https://github.com/ServiceStack/ServiceStack.Examples" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ServiceStack&#x2F;ServiceStack.Examples</a><p><a href="http://stackoverflow.com/questions/15862634/in-what-order-are-the-servicestack-examples-supposed-to-be-grokked/15869816#15869816" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;15862634&#x2F;in-what-order-ar...</a><p>It also has various other goodies, such as:<p><a href="https://github.com/ServiceStack/ServiceStack/wiki/Metadata-page" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ServiceStack&#x2F;ServiceStack&#x2F;wiki&#x2F;Metadata-p...</a><p><a href="https://github.com/ServiceStack/ServiceStack/wiki/The-IoC-container" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ServiceStack&#x2F;ServiceStack&#x2F;wiki&#x2F;The-IoC-co...</a><p><a href="https://github.com/ServiceStack/ServiceStack/wiki/Plugins" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ServiceStack&#x2F;ServiceStack&#x2F;wiki&#x2F;Plugins</a><p><a href="https://github.com/ServiceStack/ServiceStack/wiki/Clients-overview" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ServiceStack&#x2F;ServiceStack&#x2F;wiki&#x2F;Clients-ov...</a><p>It also doesn&#x27;t require ASP.NET and can run on Unix under Mono.<p>Try it, you won&#x27;t go back to WebAPI is guarantee it!
评论 #6842290 未加载