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
void applyToParams(List queryParams, Map headerParams) {
final value = apiKeyPrefix == null ? apiKey : '$apiKeyPrefix $apiKey';
if (location == 'query' && value != null) {
queryParams.add(QueryParam(paramName, value));
} else if (location == 'header' && value != null) {
headerParams[paramName] = value;
} else if (location == 'cookie' && value != null) {
headerParams.update(
'Cookie',
(existingCookie) => '$existingCookie; $paramName=$value',
ifAbsent: () => '$paramName=$value',
);
}
}
}