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

Enable cross origin requests in the Web Service REST server

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.8
    • 2.8
    • Web Services
    • MOODLE_28_STABLE
    • MOODLE_28_STABLE
    • MDL-47545-master
    • Hide

      You need a token for the Mobile Service:

      1. Enable Web Services
      2. Enable REST Protocol
      3. Enable the Mobile Service
      4. Create Token:
        1. Click on Site administration ► Plugins ► Web services ► Manage tokens
        2. Click add, select user and service (Mobile Service)
      5. Download an open this html file in your browser: https://gist.github.com/jleyva/5c2de2a21c8674dd072d
      6. Change the URL and token values, launch the script (click in Test) you should see the response in plain JSON format with the Moodle site information.
      Show
      You need a token for the Mobile Service: Enable Web Services Enable REST Protocol Enable the Mobile Service Create Token: Click on Site administration ► Plugins ► Web services ► Manage tokens Click add, select user and service (Mobile Service) Download an open this html file in your browser: https://gist.github.com/jleyva/5c2de2a21c8674dd072d Change the URL and token values, launch the script (click in Test) you should see the response in plain JSON format with the Moodle site information.

      It would be interesting to enable cross origin requests in the REST server (add support to CORS)

      The benefits will be:

      Adding CORS support should be safe since the web service end points do not use the Moodle cookie/session, authentication is done using the token and if it detects that the Moodle cookie is used is throws an exception

      The change will be minimal:

      In the send_headers method: add this line:
      https://github.com/moodle/moodle/blob/master/webservice/rest/locallib.php#L173

      header('Access-Control-Allow-Origin: *');
      

            jleyva Juan Leyva
            jleyva Juan Leyva
            Martin Dougiamas Martin Dougiamas
            Dan Poltawski Dan Poltawski
            Andrew Lyons Andrew Lyons
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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