Legitimacy is actually made out of guns.
The moment they loose consent they become the oppressors.
As long as you can hold on to being the government (guns!), you make the laws and are by definition legitimacy itself.
Democracy, e.g., election as described by customs or laws
Tradition, e.g., a monarch's son becoming the next monarch
Charisma, e.g., a charismatic leader such as a tribe leader, dictators like Hitler, etc.
The military junta currently running Burma/Myanmar has a lot of guns, but it is not legitimate.