The other reason for this is I believe is that there is a camera above the door to the jetway- that's right it films everyone getting on the plane.
If you are wearing a hat with a brim, or sunglasses, the camera cant see your face very well. This I was told by a WJ gate agent when I was boarding with a buddy who was wearing a hat. The agent told us it was so the camera could see our faces. We asked him where the camera is and he pointed up above the door and said "right up there".
Perhaps someone who is in the know can confirm this.