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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: How do you do authorization for background jobs?

3 点作者 ratpik超过 3 年前
When a flow is directly triggered by a users action, we have the Cookie&#x2F;Token of the user to do AuthN&#x2F;AuthZ.<p>However when we need to run background jobs or some asynchronous workflow on behalf of the user, we do not have the Cookie&#x2F;Token of the user. We do have the user id but not the session. How do you solve for AuthZ specifically for your background jobs and dependent microservices?

2 条评论

gregjor超过 3 年前
Generate a one-time or short-lifespan token, pass that with the user ID and simulate a login&#x2F;session.<p>For a web app I work on that does this we generate auth tokens in the database, with an associated lifetime. Tokens are long-ish hashes from random bytes. The token is passed in the URL with the user ID. The app logs in as that user, deletes the token. Expired tokens that weren&#x27;t used for some reason get purged when they expire (scheduled event running in the database).<p>You could associate the token with a specific user ID in the database, use a secret to base the hash on so you don&#x27;t need the database... multiple possible variations depending on your needs and security requirements.
akajla超过 3 年前
For this type of background job use-case (ex. some backfill, processing etc), I would think the main reason for authn&#x2F;authz would be to ensure that only the background job process can read and edit the appropriate user data. In that case, you would need some token-based machine-to-machine authz with scoped tokens that limit what data the background process can access.