From 27a6dbeeb6e4cc027596887c0176487deaeaf1ab Mon Sep 17 00:00:00 2001 From: Michael Milette Date: Mon, 27 Jan 2020 23:42:35 -0500 Subject: [PATCH] MDL-67554 oauth2: New filtered language tags for additional parameters. This adds support for new language tags in OAuth2's "Additional Parameters Included in a Login Request" field. Available tags include: Tags Example value ----------------------------- {lang} fr {LANG} FR {language} fr_ca {LANGUAGE} FR_CA {lan-guage} fr-ca {LAN-GUAGE} FR-CA --- lib/classes/oauth2/client.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/classes/oauth2/client.php b/lib/classes/oauth2/client.php index 905a751ce41..6369636355f 100644 --- a/lib/classes/oauth2/client.php +++ b/lib/classes/oauth2/client.php @@ -126,6 +126,20 @@ class client extends \oauth2_client { return []; } $result = []; + + // Replace the language tag if it appears in the string. + $lang = current_language(); + $tags = ["{lang}", "{LANG}", "{language}", "{LANGUAGE}", '{lan-guage}', '{LAN-GUAGE}']; + $langcode = [ + strtolower(substr($lang, 0, 2)), + strtoupper(substr($lang, 0, 2)), + strtolower($lang), + strtoupper($lang), + str_replace('_', '-', strtolower($lang)), + str_replace('_', '-', strtoupper($lang)), + ]; + $params = str_replace($tags, $langcode, $params); + parse_str($params, $result); return $result; }