Basic HTTP auth in actix-web 基本的HTTP身份验证在actix-web中

huangapple go评论73阅读模式
英文:

Basic HTTP auth in actix-web

问题

我真的很新于web开发,我卡在尝试在项目中使用actix-web实现简单的HTTP身份验证。我的需求如下:

  • 我不需要任何数据库来进行身份验证。只需从环境变量中获取用户名和密码,这些信息将在运行Docker容器时提供。

  • 我只需要对/api/*路由进行身份验证,其他路由应保持公开。

  • 理想情况下,应该使用基本的HTTP身份验证并将其存储在会话中。

我尝试使用actix_web_httpauth crate,但我找不到足够的文档来实现我的用例。

再次强调,这可能是一件容易的事情,但我对web开发一点都不熟悉。感谢任何帮助。

英文:

I'm really new to web development and I'm stuck trying to implement a simple HTTP auth in a project using actix-web. My needs are following:

  • I don't want/need any databases for the auth. It's enough for me to access the username and pass from enviroment variables, which will be provided when the docker container is run.

  • I just need authentication for the /api/* routes. All the other routes should stay public.

  • Ideally, it should be done using basic HTTP auth and stored in session.

I tried to use the actix_web_httpauth crate but I couldn't find enough documentation to implement in for my usecase.

Again, this is probably an easy thing to do, but I'm not at all familiar with web development. Any help is appreciated.

答案1

得分: 2

你可以看一下 这个 包。它相当简单,但也提供了更复杂问题的解决方案。

英文:

You could take a look at this crate. It is quite simple but also offers solutions for more complicated things.

答案2

得分: 1

我最终使用 actix-session 构建了一个自定义解决方案。

英文:

I ended up using the actix-session to build a custom solution.

huangapple
  • 本文由 发表于 2023年4月4日 09:29:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924845.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定