dart2.auth.http_bearer_auth.mustache Maven / Gradle / Ivy
{{>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().');
}
}
}