Olá Pessoal
O moodle já tem um plugin de autenticação SSO que já faz isso:
Deem uma olhada aqui https://moodle.org/plugins/auth_userkey
Autentica num sistema extern e já está automaticamente logado no moodle
Log in to Moodle using one time user key.
Auth plugin for organising simple one way SSO(single sign on) between moodle and your external web application. The main idea is to make a web call to moodle and provide one of the possible matching fields to find required user and generate one time login URL. A user can be redirected to this
URL to be log in to Moodle without typing username and password.