Headers missing in Request (CORS) and httpd.conf

Keywords: Moodle - AWS - Technical issue - Secure Connections (SSL/HTTPS)
bnsupport ID: da528bd8-b241-8bd2-43bb-6cd505399c50
Description:
Im trying to connect Moodle to Office 365 Teams. The issue is that Teams makes a request to Moodle, and for some reason the Headers are removed by the Server.

The request takes the form:

                method: 'POST',
                headers: {
                    'Content-Type' : 'application/x-www-form-urlencoded',
                    'Authorization' : result
                },
                mode: 'cors',
                cache: 'default'

In PHP, the function: apache_request_headers(); returns nothing. Headers should be passed through.

Ive edited the apache2/conf/bitnami/httpd.conf to permit CORS but it doesnt seem to work. I’ve added the code below:

<IfModule headers_module>
  <Directory "/opt/bitnami/moodle/local/o365/">
      AllowOverride All
      Require all granted
      Header always set Access-Control-Allow-Origin "\*"
      Header always set Access-Control-Allow-Methods "GET, OPTIONS, POST"
      Header always set Access-Control-Allow-Headers "*"
      Header always set Access-Control-Allow-Headers "Authorization"
  </Directory>
</IfModule>

some of the code seems to work, but I still do not get Headers returned.

Any help would be great?

Actually just to be clearer, this is the code I added to apache2/conf/bitnami/httpd.conf

<IfModule headers_module>
  <Directory "/opt/bitnami/moodle/local/o365/">
  AllowOverride All
  Options -Indexes +FollowSymLinks -MultiViews
  Require all granted
  Header always set Access-Control-Allow-Origin "\*"
  Header always set Access-Control-Allow-Methods "GET, OPTIONS, POST"
  Header always set Access-Control-Allow-Headers "*"
  Header always set Access-Control-Allow-Headers "Authorization"
  </Directory>
</IfModule>

Hello @bradnielsen2981,

I can’t seem to find that particular section of your configuration in the bnsupport file you shared with me, could you run again the tool so the changes are included?

Apart from that, could you try checking whether Access-Control-Allow-Origin "\*" is correct? I have never seen it with the slash. I possible configuration would be:

...
  <Directory "/opt/bitnami/moodle/local/o365/">
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "GET, OPTIONS, POST"
    Header set Access-Control-Allow-Headers "origin, x-requested-with, content-type, accept, Authorization"
  </Directory>
...

Regards,
Francisco de Paz

Ok I ran the support tool again. Here is the code:
0d37e5b6-56f3-b9bb-ed34-e4c2a190777f

I copied and pasted your code in, but still no difference.

I think i solved my problem.

I added the following to httpd.config :
SetEnvIf Authorization β€œ(.)" HTTP_AUTHORIZATION=$1
SetEnvIf Content-Type "(.
)” HTTP_CONTENT_TYPE=$1
SetEnvIf Accept β€œ(.*)” HTTP_ACCEPT=$1

as well as the code you gave me above.

1 Like

Hello @bradnielsen2981,

Great news! Thanks for sharing the solution with the community! Do not doubt to open a new thread in the future if you encounter any errors.

Regards,
Francisco de Paz

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.