本页内容

Qt Network 授权

Qt Network 授权提供了一组 API,使 Qt 应用程序能够实现常见的授权和身份验证协议。例如,应用程序可以实现访问控制,例如在不泄露用户密码的情况下,对在线账户和 HTTP 服务提供有限访问权限。

本模块侧重于OAuth 2.0,并对OpenID 提供有限支持。有关支持的协议,请参阅下文相关章节。

使用该模块

要使用 Qt 模块,需要将其库链接到项目中,既可以直接链接,也可以通过其他依赖项间接链接。包括 CMake 和 qmake 在内的多种构建工具都提供了专门的支持。

使用 CMake 构建

使用find_package() 命令在Qt6软件包中定位所需的模块组件:

find_package(Qt6 REQUIRED COMPONENTS NetworkAuth)
target_link_libraries(mytarget PRIVATE Qt6::NetworkAuth)

另请参阅“使用 CMake 构建”概述。

使用 qmake 进行构建

要配置模块以便使用 qmake 进行构建,请在项目的 .pro 文件中将该模块作为 QT 变量的值添加:

QT += networkauth

支持的授权和认证协议

Qt Network 授权模块支持以下协议的功能:

这些系统通过可信的授权服务器签发访问令牌,从而确保用户无需将凭据发送给资源,资源所有者也不直接管理用户凭据。例如,云端相册网站的用户无需担心向网站提供自己的凭据,而是由可信的授权服务通过 Web 界面来管理这些凭据。

文章与指南

许可

Qt Network 授权功能可在The Qt Company 提供的商业许可下使用。此外,该功能也可在GNU 通用公共许可证第 3 版下使用。更多详情请参阅Qt 许可。

示例

API 参考

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.