从HttpContext获取BasicAuth凭据?

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

Get BasicAuth credentials from HttpContext?

问题

你可以从 Microsoft.AspNetCore.Http.HttpContext 对象中以某种方式获取已使用的 BasicAuth 凭据吗?

英文:

Can I get the used BasicAuth credentials from a Microsoft.AspNetCore.Http.HttpContext object somehow?

答案1

得分: 3

HttpContext.Request.Headers中读取Authorization头部(ctx.Request.Headers.Authorizationctx.Request.Headers[HeaderNames.Authorization],前者是后者的别名)。它应该包含类似于Basic .....的内容,其中第二部分存储了使用Base64编码的用户ID/密码对作为凭据

英文:

Read the Authorization header from HttpContext.Request.Headers (ctx.Request.Headers.Authorization or ctx.Request.Headers[HeaderNames.Authorization] the former being alias for the latter). It should contain something like Basic ..... where the second part stores credentials as user ID/password pairs, encoded using base64.

huangapple
  • 本文由 发表于 2023年6月26日 14:57:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554208.html
匿名

发表评论

匿名网友

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

确定