Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-67554

Add support for language on OAuth2's "Additional Parameters Included in a Login Request" field

XMLWordPrintable

    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_35_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE, MOODLE_405_STABLE
    • MOODLE_405_STABLE
    • MDL-67554-master
    • Hide

      No workaround is available unless you hard-code a language (like lang=fr) but this does not help for a multi-language site.

      If I cannot specify the language, the OAuth2 provider does not necessarily appear in the right language.

      Show
      No workaround is available unless you hard-code a language (like lang=fr) but this does not help for a multi-language site. If I cannot specify the language, the OAuth2 provider does not necessarily appear in the right language.
    • Hide

      Initial setup - OAuth

      1. Follow OAuth 2 Google service to get the Client Id and Client secret.
      2. Login as admin.
      3. Navigate to Site Administrator > Server >  OAuth 2 services
      4. Create a new Google service called: Gmail - OAUTH2.
      5. Set the Client id and Client secret.
      6. Set the Scopes included in a login request value to: "openid profile email https://mail.google.com" (Without the quote).
      7. Set the Scopes included in a login request for offline access value to: "openid profile email https://mail.google.com" (Without the quote).
      8. Save changes.

      How to validate if this works:

      1. Install Moodle in English.
      2. Login as a Moodle administrator.
      3. Add the French language pack.
      4. Navigate to Site Administrator > General > Language > Language settings
      5. Set the default language to Français ‎(fr)‎.
      6. Navigate to Site Administrator > Plugin > Authentication > Manage Authentication
      7. Enable the Oauth 2 authentication.
      8. In the OAuth2 settings page, edit the Gmail - OAUTH2, add the following to the Additional Parameters Included in a Login Request field

        hl={lang}


        Note that, depending on your OAuth2 server, "hl" (HL in lowercase) may be "lang".

        lang={lang}

        Consult your OAuth2 server's documentation for more information on the correct parameter name.
        Note: See the list of examples to choose the appropriate plaintext tag.

      1. Save changes
      2. Log out of Moodle.
      3. Go to the Moodle login page
      4. Click the Google OAuth2 button/link you added (the name will vary depending on the name you gave it).
      5. VERIFY On your Google identity management login page, you should see &hl=fr in the URL.
      6. VERIFY the page uses the French language

      IMPORTANT NOTE: A bug before Moodle 3.7.2 prevented the additional parameter from being passed.

      Show
      Initial setup - OAuth Follow OAuth 2 Google service to get the Client Id and Client secret . Login as admin. Navigate to Site Administrator > Server >  OAuth 2 services Create a new Google service called: Gmail - OAUTH2 . Set the Client id and Client secret . Set the Scopes included in a login request value to: "openid profile email https://mail.google.com " ( Without the quote ). Set the Scopes included in a login request for offline access value to: "openid profile email https://mail.google.com " ( Without the quote ). Save changes. How to validate if this works: Install Moodle in English. Login as a Moodle administrator. Add the French language pack. Navigate to Site Administrator > General > Language > Language settings Set the default language to Français ‎(fr)‎. Navigate to Site Administrator > Plugin > Authentication > Manage Authentication Enable the Oauth 2 authentication. In the OAuth2 settings page, edit the Gmail - OAUTH2 , add the following to the Additional Parameters Included in a Login Request field hl={lang} Note that, depending on your OAuth2 server, "hl" (HL in lowercase) may be "lang". lang={lang} Consult your OAuth2 server's documentation for more information on the correct parameter name. Note: See the list of examples to choose the appropriate plaintext tag. Save changes Log out of Moodle. Go to the Moodle login page Click the Google OAuth2 button/link you added (the name will vary depending on the name you gave it). VERIFY On your Google identity management login page, you should see &hl=fr in the URL. VERIFY the page uses the French language IMPORTANT NOTE: A bug before Moodle 3.7.2 prevented the additional parameter from being passed.

      I work on multi-language Moodle sites (mostly English/French) and have a requirement to pass the current Moodle UI language as part of the OAuth2 login request so that the login page matches the language in Moodle. At the moment, this is not possible in Moodle.

      To address this issue, I would like to add support for a small filter that would replace a plaintext tag in the Additional Parameters field with the desired language code. For example:

      lang={lang}

      Note that, depending on your OAuth2 server, "lang" may be hl" (HL in lowercase).

      hl={lang}

      Consult your server's documentation for more information on the correct parameter name.

      The proposed solution accomplishes this by adding the following lines to the get_additional_login_parameters() function located in the lib/classes/oauth2/client.php file:

       

      // 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);

      This solution includes several forms of the tag to meet the needs of various OAuth2 system requirements. Supported tags include the following list. The value shown assumes that the current language is fr_ca but it would work for any other language:

      Tag format table

      Tag Example value
      {lang} fr
      {LANG} FR
      {language} fr_ca
      {LANGUAGE} FR_CA
      {lan-guage} fr-ca
      {LAN-GUAGE} FR-CA

       

      Notes:

      • If there is no tag in the field, the specified string is returned unaltered.
      • If the core current_language() function only returns two letters, all forms of the tag will also only return two letters.

      Let me know if you have any questions or concerns.

      Best regards,

      Michael Milette

            michael-milette Michael Milette
            michael-milette Michael Milette
            Meirza Meirza
            Huong Nguyen Huong Nguyen
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 2 hours, 1 minute
                1d 2h 1m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.