<?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>GraphQL requests 401 Unauthorized with OAuth2 Bearer token</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120643218" />
  <subtitle>GraphQL requests 401 Unauthorized with OAuth2 Bearer token</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=120643218</id>
  <updated>2026-05-16T02:37:36Z</updated>
  <dc:date>2026-05-16T02:37:36Z</dc:date>
  <entry>
    <title>RE: GraphQL requests 401 Unauthorized with OAuth2 Bearer token</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120656859" />
    <author>
      <name>Graziano Liberati</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120656859</id>
    <updated>2021-03-02T09:54:41Z</updated>
    <published>2021-03-02T08:59:55Z</published>
    <summary type="html">&lt;p&gt;Hello Javier,&lt;/p&gt;
&lt;p&gt;I have already enabled all the scopes.&lt;/p&gt;
&lt;p&gt;Thanks to your suggestion I have solved the problem.&lt;/p&gt;
&lt;p&gt;The problem was that I did not added the  Service Access Policy
  strating with OAUTH2_ granting the access to the services.&lt;/p&gt;
&lt;p&gt;Thanks a lot for your support! It has been very helpful!&lt;/p&gt;</summary>
    <dc:creator>Graziano Liberati</dc:creator>
    <dc:date>2021-03-02T08:59:55Z</dc:date>
  </entry>
  <entry>
    <title>RE: GraphQL requests 401 Unauthorized with OAuth2 Bearer token</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120656802" />
    <author>
      <name>Javier De Arcos</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120656802</id>
    <updated>2021-03-18T06:11:35Z</updated>
    <published>2021-03-02T06:53:24Z</published>
    <summary type="html">&lt;p&gt;Your configuration seems completely correct and a probe is that you
  were able to obtain the token.&lt;/p&gt;
&lt;p&gt;Taking this into account and reading the error message could be a
  problem with scopes. Have you select the right scope to allow access
  to this information?&lt;/p&gt;
&lt;p&gt;In this case I think you should select: User Administration -&amp;gt;
  read data on behalf&lt;/p&gt;
&lt;p&gt;
  &lt;img src="/documents/14/0/Captura+de+pantalla+2021-03-02+a+las+7.50.16.png/71bef750-4764-124a-233b-ce4f193c99e9?t=1614667908107&amp;amp;imagePreview=1" /&gt;&lt;/p&gt;
&lt;p&gt;In case you need something more custom you should add a Service
  Access Policy strating with OAUTH2_ and you will be able to select it
  as a Scope for your OAUTH configuration&lt;/p&gt;</summary>
    <dc:creator>Javier De Arcos</dc:creator>
    <dc:date>2021-03-02T06:53:24Z</dc:date>
  </entry>
  <entry>
    <title>GraphQL requests 401 Unauthorized with OAuth2 Bearer token</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120643217" />
    <author>
      <name>Graziano Liberati</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=120643217</id>
    <updated>2021-02-23T18:07:18Z</updated>
    <published>2021-02-23T18:06:08Z</published>
    <summary type="html">&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I am using Liferay 7.3 GA6, using the OAuth 2 administration panel I
  have configured an application as the following image.&lt;/p&gt;
&lt;p&gt;
  &lt;img src="/documents/14/120368684/Capture+2021-02-23+at+18.53.54.png/812c84ff-51a9-aa56-f2c0-4a730edee52e?t=1614102877998&amp;amp;imagePreview=1" /&gt;&lt;/p&gt;
&lt;p&gt;Then I have tried to perform the following graphql calls.&lt;/p&gt;
&lt;p&gt;1. Obtain the oauth2 token (success)&lt;/p&gt;
&lt;p&gt;curl --location --request POST 'https://&amp;lt;host&amp;gt;/o/oauth2/token'
  \&lt;br /&gt;--header 'Content-Type: application/x-www-form-urlencoded'
  \&lt;br /&gt;--data-urlencode 'client_id=id1234' \&lt;br /&gt;--data-urlencode
  'client_secret=secret1234' \&lt;br /&gt;--data-urlencode
  'grant_type=password' \&lt;br /&gt;--data-urlencode
  'username=&amp;lt;emailaddress&amp;gt;' \&lt;br /&gt;--data-urlencode 'password=&amp;lt;password&amp;gt;'&lt;/p&gt;
&lt;p&gt;I have replaced real data with &amp;lt;fake data&amp;gt;.&lt;/p&gt;
&lt;p&gt;This operation is successfull and I obtain the access token and the
  refresh token.&lt;/p&gt;
&lt;p&gt;2. invoke the graphql operation (failed)&lt;/p&gt;
&lt;p&gt;curl --location --request POST 'https://&amp;lt;host&amp;gt;/o/graphql'
  \&lt;br /&gt;--header 'Authorization: Bearer
  9c7222375513be53a5ef5be5471961d9a3627c1e27ab8aceb92edc43218ea'
  \&lt;br /&gt;--header 'Content-Type: application/json' \&lt;br /&gt;--data-raw
  '{&amp;quot;query&amp;quot;:&amp;quot;{\n site(siteKey: \&amp;quot;38413\&amp;quot;){\n
  id\n name\n }\n}&amp;quot;,&amp;quot;variables&amp;quot;:{}}'&lt;/p&gt;
&lt;p&gt;Reading the documentation I see that the access token should be
  passed through the authorization header. Anyway I obtain the following error&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
    &amp;quot;errors&amp;quot;: [
        {
            &amp;quot;message&amp;quot;: &amp;quot;Exception while fetching data (/site) : java.lang.SecurityException: Access denied to com.liferay.portal.kernel.service.GroupService#getGroup&amp;quot;,
            &amp;quot;locations&amp;quot;: [],
            &amp;quot;errorType&amp;quot;: &amp;quot;DataFetchingException&amp;quot;,
            &amp;quot;path&amp;quot;: null,
            &amp;quot;extensions&amp;quot;: {
                &amp;quot;exception&amp;quot;: {
                    &amp;quot;errno&amp;quot;: 401
                },
                &amp;quot;code&amp;quot;: &amp;quot;Unauthorized&amp;quot;
            }
        }
    ],
    &amp;quot;data&amp;quot;: {
        &amp;quot;site&amp;quot;: null
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Can anyone help me on this please?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br /&gt;Graziano&lt;/p&gt;</summary>
    <dc:creator>Graziano Liberati</dc:creator>
    <dc:date>2021-02-23T18:06:08Z</dc:date>
  </entry>
</feed>
