unwrapAuthHeaderValue function
Returns the auth key from an auth value that has potentially been wrapped. This operation is the inverse of wrapAsBasicAuthHeaderValue and wrapAsBearerAuthHeaderValue. If null is provided, null is returned.
Implementation
String? unwrapAuthHeaderValue(String? authValue) {
if (authValue == null) return null;
if (isWrappedBasicAuthHeaderValue(authValue)) {
// Basic auth value was wrapped, decode from base64.
var parts = authValue.split(' ');
return utf8.decode(base64.decode(parts[1]));
} else if (isWrappedBearerAuthHeaderValue(authValue)) {
// Bearer auth value was wrapped, just return the token part.
var parts = authValue.split(' ');
return parts[1];
} else {
// auth value was not wrapped, return as is
return authValue;
}
}