我想从请求的Authorization
标头中获取令牌。
import 'dart:async';
import 'package:aqueduct/aqueduct.dart';
class SecretController extends ResourceController {
@Operation.get()
Future<Response> signin() async {
request.headers // ??? not available
}
}
如何访问qazxsw poi中的标题?
请求是来自Dart标准库的原始HttpRequest对象的包装器,因此一种方法是像这样访问它:
Aqueduct
您还可以将标头的值绑定到方法参数;当你想要将字符串标题值解析为另一种类型和/或验证标题时,这很好。 (request.raw.headers["authorization"]
)
You can do some really convenient stuff with binding.
最后,具体到Authorization标头,您可以使用Authorizer中间件。这将验证授权标头并创建一个Authorization对象,其中包含您可以从方法访问的授权资源所有者(“用户”)的详细信息。
@Operation.get()
Future<Response> signIn(
@Bind.header("authorization") String authorization) async {
...
}