isAnthropicAuthEnabled function

bool isAnthropicAuthEnabled()

Whether direct 1P auth (OAuth) is enabled.

Implementation

bool isAnthropicAuthEnabled() {
  if (isBareMode()) return false;

  if (Platform.environment['ANTHROPIC_UNIX_SOCKET'] != null) {
    return Platform.environment['MAGE_OAUTH_TOKEN'] != null;
  }

  final is3P = isUsing3PServices();

  final hasExternalAuthToken =
      Platform.environment['ANTHROPIC_AUTH_TOKEN'] != null ||
      getConfiguredApiKeyHelper() != null ||
      Platform.environment['MAGE_API_KEY_FILE_DESCRIPTOR'] != null;

  final apiKeyResult = getAnthropicApiKeyWithSource(
    skipRetrievingKeyFromApiKeyHelper: true,
  );
  final hasExternalApiKey =
      apiKeyResult.source == ApiKeySource.anthropicApiKey ||
      apiKeyResult.source == ApiKeySource.apiKeyHelper;

  final shouldDisableAuth =
      is3P ||
      (hasExternalAuthToken && !isManagedOAuthContext()) ||
      (hasExternalApiKey && !isManagedOAuthContext());

  return !shouldDisableAuth;
}