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

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

There is a newer version: 7.9.0
Show newest version
{{>header}}
{{>part_of}}
typedef HttpBearerAuthProvider = String Function();

class HttpBearerAuth implements Authentication {
  HttpBearerAuth();

  dynamic _accessToken;

  dynamic get accessToken => _accessToken;

  set accessToken(dynamic accessToken) {
    if (accessToken is! String && accessToken is! HttpBearerAuthProvider) {
      throw ArgumentError('Type of Bearer accessToken should be a String or a String Function().');
    }
    this._accessToken = accessToken;
  }

  @override
  void applyToParams(List queryParams, Map headerParams) {
    if (_accessToken is String) {
      headerParams['Authorization'] = 'Bearer $_accessToken';
    } else if (_accessToken is HttpBearerAuthProvider) {
      headerParams['Authorization'] = 'Bearer ${_accessToken()}';
    } else {
      throw ArgumentError('Type of Bearer accessToken should be a String or a String Function().');
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy