King Hassan, Morocco's ruling monarch for the last 22 years, has been compared to his old friend, the deposed shah of Iran. Now, congressional critics of the Carter administration's Moroccan policy are making that country the latest test of the administration's resolve to stand by longtime U.S. allies.

The comparisons to the shah, and to a lesser extent to deposed Nicaraguan President Anastasio Somoza, have reopened a broader debate within Congress and the administration as to whether the United States is doing too much or not enough to support proven friends of U.S. interests abroad.

Intelligence reports are known to say that Morocco's prolonged and frustrating war in the Sahara, which has already drained the Moroccan economy, could prove the impetus for another coup attempt against Hassan by the disgruntled Moroccan military.

Reliable sources say the intelligence reports have found Hassan's base of support eroding because of the war, especially among military officers who feel that the king is not wholeheartedly pursuing a victory in the Sahara.

Sources quoting the intelligence reports say that if the Sahara war drags on much past this fourth burning desert summer, it could bring the end of Morocco's 300-year-old monarchy and replace it with some form of military authority.

Hassan is considered, as was the shah of Iran, a valuable assett to the Carter administration in the Middle East, and the loss of that proWestern, Arab moderate would be a crippling blow for U.S. Mideast peace initiatives.

And Morocco -- located astride the southern shore of the Gibralter Strait -- is as strategically vital to the North African region as Iran is to the Persian Gulf.

While the shah's troubles stemmed from religious opposition from Iran's dominant Moslem majority, discontent with Hassan has risen from the military, the secular political opposition parties of both the right and the left, and the government controlled parliament.

Hassan's current woes center around his territorial designs aimed at annexing the vast and largely uninhabited Western Sahara region, a matter of national pride in Morocco. A group called the Polisario Front has been fighting to free the Sahara from Moroccan administrative control.

The Sahara conflict, and the specter of another U.S. ally in trouble at home, has raised a new policy dilemma for the Carter administration. The king has requested more U.S. arms -- specifically OV10 reconnaissance planes -- to help him beat back the insurgency. The administration must decide whether to sell the king what he wants, or risk seeing one of the United States' oldest and most consistent supporters fall victim to an eroding political base.

Rep. Stephen Solarz (D-N.Y.) said, "Policy on the Western Sahara is up for grabs at the moment. People are really rethinking positions."

The administration's refusal so far to lift current arms sales restrictions has been the source of bitterness and resentment in Rabat, where some Morocans feel betrayed by this country. In Washington, pro-Moroccan critics of current administration policy of restraint are making Morocco the next test of the Carter administration's foreign policy.

"It falls into the same category as Iran and Nicaragua," said Rep. Edward J. Derwinski (R-Ill.). "We're letting down our friends. The Carter policy towards Morocco is one of the sad chapters of American foreign policy."

For the United States, the policy alternatives can be seen as choice between pursuing a Middle East policy or an Africa policy.

Pursuing a Middle East policy would mean siding with Morocco in the conflict, since Hassan has been a consistent supporter of peace initiatives there and has so far kept Morocco out of the group of the socalled rejectionist states, despite wooing from Saudi Arabia. Hassan is a personal friend of Egypt's President Anwar Sadat, and an important voice for Arab moderation.

From an African context, the administration would have to side with the 33 states of the Organization of African Unity, which last month called for a cease fire on the Sahara and a referendum of Saharawi sovereignty. A referendum would almost certainly lead to a vote for total independence for the territory, and the Moroccan government wasted no time in rejecting the idea and labeling the OAU resolution "null and void."

The Morocco question has also raised the problem of a longtime ally now in need of military assistance.

As Assistant Secretary of State Harold Saunders put it, "Once again, the United States found itself on the horns of a dilemma not of its own making."

The move to push the Carter administration toward more open support for Hassan was reflected in the 1980 foreign assistance bill still in conference. The administration had requested a $15 million cut in military sales credits to Morocco, but the conferees instead approved an amendment by Sen. Jacob Javits (R-N.Y.) -- who recently visited Morocco -- and restored Hassan's full $45 million military aid package.

The issues in the desert are a conflict between Morocco's historic claims to the region and the Polisario's claim that the Sahawri people have been denied their right to self-determination. Policymakers here and in Rabat concede that a compromise between the two positions is about as likely as a cool, crisp Sahara summer.

Hassan's political troubles -- what some diplomats refer to as "Morocco's Vietnam" -- are largely the result of the broad based national sentiment he built, making annexation of the Sahara a rallying cry for a "Greater Morocco."

Following Hassan's successful GREEN march" in 1975, when 350,000 Moroccans marched onto the territory as a rebuke to Spanish colonialism, Hassan has found the national constituency for the war now clamoring for a harder line than he would like to take.

Military officers in the Sahara have been complaining they don't have a free enough hand to pursue the Polisario guerrillas. Hassan has all military decisions approved by him personally, partly out of fear that frustrated officers might pursue the guerrillas into their bases in Algeria and touch off a wider war for which Morocco is not ready.

To demonstrate the widespread support for the war, and to blunt the mounting opposition, Hassan established a National Defense Council consisting of two representatives from every legal political party. A day later, parliament voted in favor of "hot pursuit" raids into Algerian territory, although the king has been reluctant to engage his better equipped, Soviet backed neighbor.

The war also has exacted an economic toll on Morocco, dramatized by a series of recent strikes for pay increases and underscored by Hassan's postponement last year of a new five year economic plan because of the high cost of the war.

Now with Mauritania deciding to reach an agreement with the Polisario, Morocco's already over extended army of 80,000 must be stretched even further, if Hassan carries through on his promise to annex Mauritania's southern third of the disputed territory.

Rep. Solarz, whose House Africa subcommittee recently held hearings on the region, said, "There are those in Congress who feel that the U.S. let down the shah and Somoza. There are others who see this as a grab by Morocco of territory that doesn't belong to it and to help Morocco do that would be a betrayal of our principles."