<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Looking for a workaround for CORS when OAuth enabled with REST</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=113586257" />
  <subtitle>Looking for a workaround for CORS when OAuth enabled with REST</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=113586257</id>
  <updated>2026-04-04T03:13:56Z</updated>
  <dc:date>2026-04-04T03:13:56Z</dc:date>
  <entry>
    <title>RE: Looking for a workaround for CORS when OAuth enabled with REST</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113707557" />
    <author>
      <name>Eric COQUELIN</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113707557</id>
    <updated>2019-05-22T12:00:01Z</updated>
    <published>2019-05-22T12:00:01Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;After analyzing, it appears that Whiteboard became more strict. Now it requires to se target&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(property = { "osgi.jaxrs.extension=true",
&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;"osgi.jaxrs.name=LiferayCorsFilter", "osgi.jaxrs.application.select=(osgi.jaxrs.name=*)" }, immediate = true, configurationPid = "com.ajizan.liferay.cors.configuration.LiferayCORSConfiguration", service = ContainerResponseFilter.class)&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Now it works&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Eric COQUELIN</dc:creator>
    <dc:date>2019-05-22T12:00:01Z</dc:date>
  </entry>
  <entry>
    <title>RE: Looking for a workaround for CORS when OAuth enabled with REST</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113707216" />
    <author>
      <name>Eric COQUELIN</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113707216</id>
    <updated>2019-05-22T11:35:47Z</updated>
    <published>2019-05-22T11:35:47Z</published>
    <summary type="html">Hello community,&lt;br /&gt;I just upgraded to 7.1 GA4 and the code above doesn&amp;#39;t work anymore.&lt;br /&gt;It looks like the ContainerResponseFilter is no more taken into account even if the component is properly registered.&lt;br /&gt;On the release notes, I haven&amp;#39;t found any breaking change or anything related to ContainerResponseFilter, thus it is either a bug either a choice which has not been documented.&lt;br /&gt;Can anyone help?&lt;br /&gt;Thank you</summary>
    <dc:creator>Eric COQUELIN</dc:creator>
    <dc:date>2019-05-22T11:35:47Z</dc:date>
  </entry>
  <entry>
    <title>RE: Looking for a workaround for CORS when OAuth enabled with REST</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113592654" />
    <author>
      <name>Eric COQUELIN</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113592654</id>
    <updated>2019-05-10T09:47:40Z</updated>
    <published>2019-05-10T09:47:40Z</published>
    <summary type="html">Hi Christoph,&lt;br /&gt;&lt;br /&gt;Thank you for replying.&lt;br /&gt;&lt;br /&gt;I know there are third party solutions such as reverse proxy but I want to find a solution with Liferay. This is also an approach to learn more about how the security works with Liferay.&lt;br /&gt;&lt;br /&gt;I found some additional mechanisms.&lt;br /&gt;&lt;br /&gt;First of all, It seems I can&amp;#39;t avoid the CORS Filter. I understand that I should avoid giving access to any origin for security reason. But that component is required. Then, I need to add a new VerifierAuth in the pipeline otherwise my OPTIONS requests are rejected.&lt;br /&gt;&lt;br /&gt;Can you please have a look at my source code that I am pleased to share with the community ?&lt;br /&gt;&lt;br /&gt;&lt;a href="https://github.com/Ajizan/liferay-cors"&gt;https://github.com/Ajizan/liferay-cors&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;By the way, If I try to restrict the filter to a given URL using &amp;#34;auth.verifier.LiferayOptionsAuthVerifier.urls.includes&amp;#34;, it doesn&amp;#39;t apply. My REST service are deployed on /o/immobilio/... but if I set the above URL to &amp;#34;/o/immobilio/*&amp;#34; or even &amp;#34;/o/*&amp;#34;, it doesn&amp;#39;t work. And when I log the context path, it gives me &amp;#34;/o/immobilio&amp;#34;, then I don&amp;#39;t understand.&lt;br /&gt;&lt;br /&gt;Thank you in advance for any feedbacks.</summary>
    <dc:creator>Eric COQUELIN</dc:creator>
    <dc:date>2019-05-10T09:47:40Z</dc:date>
  </entry>
  <entry>
    <title>RE: Looking for a workaround for CORS when OAuth enabled with REST</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113586621" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113586621</id>
    <updated>2019-05-09T17:51:33Z</updated>
    <published>2019-05-09T17:51:33Z</published>
    <summary type="html">Not sure if this helps you, but I usually do stuff like this in a reverse proxy.  It&amp;#39;s quite easy to do it there and also very flexible.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: It&amp;#39;s not best practice to add &amp;#34;Access-Control-Allow-Origin: *&amp;#34; header, except maybe in development environments.&lt;br /&gt;I usually use something like this. Basically a whitelist of domains that may access my service using cors. The same idea can, of course, be used in other implementations too.&lt;br /&gt;&lt;br /&gt;https://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2019-05-09T17:51:33Z</dc:date>
  </entry>
  <entry>
    <title>Looking for a workaround for CORS when OAuth enabled with REST</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113586256" />
    <author>
      <name>Eric COQUELIN</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113586256</id>
    <updated>2019-05-09T17:38:43Z</updated>
    <published>2019-05-09T17:38:43Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Dear Community,&lt;br&gt;&lt;br&gt;I have created some JAXRS services which work well. Then, I decided to apply some security using OAuth.&lt;br&gt;&lt;br&gt;Using a Postman, I can perform any request without any issue but when sending same requests from an Angular application, it starts with an OPTION request for CORS (Cross Origin) and it fails with a 403. I disabled OAuth and added a filter to enable CORS&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(property = { "osgi.jaxrs.extension=true",
        "osgi.jaxrs.name=Filter.CORS" }, service = ContainerResponseFilter.class)
public class CorsFilter implements ContainerResponseFilter {

    private Log _log = LogFactoryUtil.getLog(getClass());

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {

        if (_log.isDebugEnabled()) {
            _log.debug("Writing CORS headers");
        }

        MultivaluedMap&amp;lt;string, object&amp;gt; headers = responseContext.getHeaders();
        headers.add("Access-Control-Allow-Origin", "*");
        headers.add("Access-Control-Allow-Headers", "Origin,Content-Type,Accept,Authorization,content-type");
        headers.add("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS,HEAD,PATCH");
        headers.add("Access-Control-Max-Age", "1209500");

    }

}&amp;lt;/string,&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Then my requests work from my Angular App as the given filter allows CORS.&lt;br&gt;&lt;br&gt;When enabling again OAuth, it fails again. It looks like the servlet request is being catched on top of this Filter (no log displayed anymore) and it doesn't work obviously.&lt;br&gt;&lt;br&gt;With 6.2, we had to setup a filter at Tomcat web.xml but I assume things have improved.&lt;br&gt;&lt;br&gt;Can anyone share with me any tips to solve this issue properly in the DXP way ?&lt;br&gt;&lt;br&gt;Thank you,&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Eric COQUELIN</dc:creator>
    <dc:date>2019-05-09T17:38:43Z</dc:date>
  </entry>
</feed>
