dart2.auth.api_key_auth.mustache Maven / Gradle / Ivy
{{>header}}
{{>part_of}}
class ApiKeyAuth implements Authentication {
ApiKeyAuth(this.location, this.paramName);
final String location;
final String paramName;
String apiKeyPrefix = '';
String apiKey = '';
@override
Future applyToParams(List queryParams, Map headerParams,) async {
final paramValue = apiKeyPrefix.isEmpty ? apiKey : '$apiKeyPrefix $apiKey';
if (paramValue.isNotEmpty) {
if (location == 'query') {
queryParams.add(QueryParam(paramName, paramValue));
} else if (location == 'header') {
headerParams[paramName] = paramValue;
} else if (location == 'cookie') {
headerParams.update(
'Cookie',
(existingCookie) => '$existingCookie; $paramName=$paramValue',
ifAbsent: () => '$paramName=$paramValue',
);
}
}
}
}