bearerToken static method
Load a JSON file and create a FunctionAuth that sets a Bearer token
via the Authorization header.
Implementation
static Future<FunctionAuth> bearerToken(
String path, {
String? section,
String tokenKey = 'token',
String headerName = 'Authorization',
String headerPrefix = 'Bearer ',
}) async {
final data = await _load(path, section);
final token = data[tokenKey];
if (token == null) {
throw FileSecretsError(
'Missing "$tokenKey" in ${_desc(path, section)}',
);
}
return FunctionAuth((req) {
return req.copyWith(
headers: req.headers.copy()..[headerName] = '$headerPrefix$token',
);
});
}