microsoft / o365-moodle

Office 365 and Azure Active Directory plugins for Moodle
GNU General Public License v3.0
180 stars 136 forks source link

Get current access token in custom activity plugin #2444

Open serumk opened 8 months ago

serumk commented 8 months ago

I'm writing an activity plugin and need a current (=not expired) access token for accessing a third-party-API that authenticates against the same IDP as Moodle. If I see this right, the OIDC-plugin writes the token after a successful login into the auth_oidc_token table but doesn't update it anymore, so after a few minutes the token is expired. How do I get a current access token in my plugin? Any pointer would be highly appreciated!

weilai-irl commented 7 months ago

Hi @serumk

Tokens stored in auth_oidc_token table are updated upon user login by making call to function updatetoken() at https://github.com/microsoft/o365-moodle/blob/e0eec2d974d8864f8a2dc0074764b408b51985c5/auth/oidc/classes/loginflow/base.php#L698-L721. The function is called from handlelogin() function in classes/loginflow/authcode.php at https://github.com/microsoft/o365-moodle/blob/e0eec2d974d8864f8a2dc0074764b408b51985c5/auth/oidc/classes/loginflow/authcode.php#L652.

Regards, Lai