getAuthorizationHeaderValue method
Returns future that resolves "Authorization" header value used for authenticating.
Throws DataException if credential is not valid.
Implementation
// This method returns future to make sure in future we could use the
// [Credential] interface for OAuth2.0 authentication too - which requires
// token rotation (refresh) that's async job.
Future<String> getAuthorizationHeaderValue() {
if (!isValid()) {
throw DataException(
'Saved credential for "$url" pub repository is not supported by '
'current version of Dart SDK.',
);
}
final environment = env;
if (environment != null) {
final value = Platform.environment[environment];
if (value == null) {
throw DataException(
'Saved credential for "$url" pub repository requires environment '
'variable named "$env" but not defined.',
);
}
return Future.value('Bearer $value');
}
return Future.value('Bearer $token');
}