All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dart2.auth.api_key_auth.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>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',
      );
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy