It is likely not legal. While an employer may set dress codes, and so as a general matter could, for example, bar sunglasses, an employer is also obligated by law (e.g. the Americans with Disabilities Act) to make a "reasonable accommodation" to employee medical conditions and disabilities. A reasonable accommodation includes a change in rules which is not too disruprtive or expensive for the employer but which helps compensate for the employee's disability or condition. It is difficult to see how letting you wear sunglasses is expensive or disruptive for them; certaintly, they could set some rules for what kinds of glasses are ok (e.g. have to look "professional"; no "Terminator"-style glasses, no mirrorrshades, etc.), but they should have to allow the glasses, the same way that UPS had to allow employees with a medical condition which causes painful infections if the are clean shaven to have beards (but could set grooming standards and require neat, short beards). If your employer will not let you have the glasses, contact the federal EEOC or your state's equal/civil rights agency about filing a complaint.