getAuthHeaders function
Get authentication headers for API requests.
isSubscriber: whether the user is a Neomage AI subscriber
getOAuthAccessToken: callback to get OAuth token
getApiKey: callback to get the API key
oauthBetaHeader: the beta header value for OAuth
Implementation
AuthHeaders getAuthHeaders({
required bool isSubscriber,
String? Function()? getOAuthAccessToken,
String? Function()? getApiKey,
String oauthBetaHeader = '',
}) {
if (isSubscriber) {
final accessToken = getOAuthAccessToken?.call();
if (accessToken == null || accessToken.isEmpty) {
return const AuthHeaders(headers: {}, error: 'No OAuth token available');
}
return AuthHeaders(
headers: {
'Authorization': 'Bearer $accessToken',
if (oauthBetaHeader.isNotEmpty) 'anthropic-beta': oauthBetaHeader,
},
);
}
final apiKey = getApiKey?.call();
if (apiKey == null || apiKey.isEmpty) {
return const AuthHeaders(headers: {}, error: 'No API key available');
}
return AuthHeaders(headers: {'x-api-key': apiKey});
}