Fix NPE when authentication is needed

Fix NPE when authentication is needed