Single Sign On resource

Please especially review the authentication logic. I mimicked login to the best of my abilities but I am not confident that I understood all the complexities.