Support Google Apps authentication.
Fix bugs introduced by the previous patch.