且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTTP 401不使用HTTP基本身份验证时未授权?

更新时间:2023-12-01 08:12:22

您假设www-authenticate值必须是基本值.您可以返回诸如"API密钥"之类的其他值作为需要进行的身份验证的类型.因此,请随时返回401和带有其他值的www-authenticate标头.您甚至可以返回带有不同值的多个标头,以指示您的应用程序支持的身份验证的不同类型.

You are assuming that the www-authenticate value needs to be basic. You can return a different value like "API-key" as the type of auth that needs to happen. So feel free to return 401 and www-authenticate header with some other value. You can even return multiple headers with different values indicating the different types of authentication that your app supports.