Dart 中最易用的授权标头管理库!
1. 关于
AuthorizationHeader 是一个开源的 Dart 库。
使用 AuthorizationHeader,您可以轻松地管理应用程序上的授权标头。
AuthorizationHeader 库提供了生成授权标头的通用功能,用于 Basic 或 Bearer 授权。代理的 Proxy-Authorization 也受支持。
通过使用 AuthorizationHeader 库,您无需再进行冗余的实现或研究来生成授权标头!
1.1. 支持
1.1.1. Authorization Header
| 名称 |
|---|
| Authorization |
| Proxy-Authorization |
1.1.2. 授权类型
| 名称 | RFC |
|---|---|
| 基础 | RFC 7617 |
| Bearer | RFC 6750 |
1.2. 简介
1.2.1. 安装库
使用 Dart
dart pub add authorization_header
使用 Flutter
flutter pub add authorization_header
1.2.2. 导入它
import 'package:authorization_header/authorization_header.dart';
1.2.3. 使用 AuthorizationHeader
AuthorizationHeader 可以与 http 包结合使用,如下所示。
import 'package:authorization_header/authorization_header.dart';
import 'package:http/http.dart' as http;
void main() async {
/// You can switch between Default and Proxy in the constructor.
final authHeader = Auth.of().bearer(token: 'test_token');
final proxyAuthHeader = Auth.ofProxy().bearer(token: 'test_token');
print(authHeader); // -> name: Authorization, value: Bearer test
print(proxyAuthHeader); // -> name: Proxy-Authorization, value: Bearer test
await http.post(
Uri.parse('https://test.com'),
headers: {
authHeader.name: authHeader.value,
proxyAuthHeader.name: proxyAuthHeader.value,
},
);
}
1.3. 许可证
Copyright (c) 2021, Kato Shinya. All rights reserved.
Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
1.4. 更多信息
AuthorizationHeader 由加藤慎也设计和实现。