<div dir="ltr">well in the latest keycloak.json you pasted a &quot; is missing for the line : <br><br>&quot;resource&quot;: <span style="color:rgb(80,0,80);font-size:12.8px">nodejs-connect</span>&quot;,<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 8, 2016 at 9:13 AM, Deepak Garg <span dir="ltr">&lt;<a href="mailto:deepakgarg.garg@gmail.com" target="_blank">deepakgarg.garg@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Sebi,<div><br></div><div>I did the same thing and defined a new client/resource called &quot;<span style="color:rgb(80,0,80);font-size:12.8px">nodejs-connect</span>&quot; and set the access type &quot;bearer-only&quot; .<div><br><div><br></div><div>but when I am running my node server, it is throwing an error</div><div><span style="font-size:12.8px">&quot;SyntaxError: </span><b style="font-size:12.8px">Unexpected token u</b><div style="font-size:12.8px">    at Object.parse (native)</div><div style="font-size:12.8px">    at Config.loadConfiguration (D:\Sample Projects\NodePrototypes\NodeSa<wbr>mple\no</div><div style="font-size:12.8px">de_modules\keycloak-connect\no<wbr>de_modules\keycloak-auth-utils<wbr>\lib\config.js:53:23</div><div style="font-size:12.8px">)</div><div style="font-size:12.8px">    at new Config (D:\Sample Projects\NodePrototypes\NodeSa<wbr>mple\node_modules\key</div><div style="font-size:12.8px">cloak-connect\node_modules\key<wbr>cloak-auth-utils\lib\config.<wbr>js:40:10)</div><div style="font-size:12.8px">    at new Keycloak (D:\Sample Projects\NodePrototypes\NodeSa<wbr>mple\node_modules\k</div><div style="font-size:12.8px">eycloak-connect\index.js:61:17<wbr>)&quot;</div></div></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><span style="font-size:small"> Can you look into this below keycloak.json file. If I have specified whether it is correct?</span><br></div><div><br></div><div><b>Keycloak.json</b></div><div><br></div><div><div>{</div><div>  &quot;realm&quot;: &quot;<span style="color:rgb(80,0,80);font-size:12.8px">nodejs-example</span>&quot;,</div><div>  &quot;realm-public-key&quot;: &quot;<wbr>MIGfMA0GCSqGSIb3DQEBAQUAA4GNAD<wbr>CBiQKBgQCtvV0qb8+<wbr>A0pxKoRpToHhc6srY4PyoX/<wbr>pwgmR7HyV0PeUw/<wbr>DgyyCI1Wmvw3T15kWw7Q84gX8IL0wD<wbr>NtfmbhMPmz5umVeul3LzacjU9qfDqG<wbr>96Wirn7+<wbr>5Je1VieH5wRX3mtyQ2TboRVpjFD0fw<wbr>d063FYOtCynfDSS0Uo6YgjWs8QwIDA<wbr>QAB&quot;,</div><div> <b> &quot;bearer-only&quot;: true,</b></div><div>  &quot;auth-server-url&quot;: &quot;<a href="http://localhost:9090/auth" target="_blank">http://localhost:9090/auth</a>&quot;,</div><div>  &quot;ssl-required&quot;: &quot;none&quot;,</div><div>  &quot;resource&quot;: <span style="color:rgb(80,0,80);font-size:12.8px">nodejs-connect</span>&quot;,</div><div>   &quot;enable-cors&quot; : true,</div><div>   &quot;credentials&quot;: {</div><div>    &quot;secret&quot;: &quot;6b620304-b4a9-4007-8701-<wbr>d3abb3537598&quot;</div><div>  }</div><div> }</div></div><div><br></div><div><br></div><div>Thanks,</div><div>Deepak</div><div><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 8, 2016 at 12:34 PM, Sebastien Blanc <span dir="ltr">&lt;<a href="mailto:sblanc@redhat.com" target="_blank">sblanc@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>Hi,<br><br></div>Is your NodeJS app just a REST backend without any frontend ? In this case you should put &quot;bearer-only: true&quot; and then it is the responsibility of your frontend or any other service to pass the token to your rest service. <br><br></div>Sebi<br><div> <br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Mon, Aug 8, 2016 at 7:03 AM, Deepak Garg <span dir="ltr">&lt;<a href="mailto:deepakgarg.garg@gmail.com" target="_blank">deepakgarg.garg@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div><div dir="ltr"><span style="font-size:12.8px">I have created a rest api in node js and used keycloak-connect npm packge.</span><br style="font-size:12.8px"><span style="font-size:12.8px">I have mapped the nodejs middleware with keycloak middleware and just put</span><br style="font-size:12.8px"><span style="font-size:12.8px">keycloak.Protect() method in side api method.</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">When the user is not logged in, it shows a login screen and ask for</span><br style="font-size:12.8px"><span style="font-size:12.8px">credential. After login, it shows the result. but I don&#39;t want to show a</span><br style="font-size:12.8px"><span style="font-size:12.8px">login screen if user is not already logged in. Instead of that i want to</span><br style="font-size:12.8px"><span style="font-size:12.8px">pass the token and get access based upon that token?</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">Do i need to do anything in the API code so that it will accept the user</span><br style="font-size:12.8px"><span style="font-size:12.8px">token?</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">I like to use this api through User interface and set the access type</span><br style="font-size:12.8px"><span style="font-size:12.8px">bearer for this service in the keycloak admin.</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">see the example:</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">  var express = require(&#39;express&#39;);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    var apiRoutes = express.Router();</span><br style="font-size:12.8px"><span style="font-size:12.8px">    var User = require(&#39;../models/user&#39;);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    var jwt = require(&#39;jsonwebtoken&#39;);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    var faker = require(&#39;faker&#39;);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    var session = require(&#39;express-session&#39;);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    var Keycloak = require(&#39;keycloak-connect&#39;);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    var hogan = require(&#39;hogan-express&#39;);</span><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">    var memoryStore = new session.MemoryStore();</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">    var keycloak = new Keycloak({store: memoryStore});</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">        app.use(session({</span><br style="font-size:12.8px"><span style="font-size:12.8px">            secret: app.get(&#39;superSecret&#39;),</span><br style="font-size:12.8px"><span style="font-size:12.8px">            resave: false,</span><br style="font-size:12.8px"><span style="font-size:12.8px">            saveUninitialized: true,</span><br style="font-size:12.8px"><span style="font-size:12.8px">            store: memoryStore</span><br style="font-size:12.8px"><span style="font-size:12.8px">        }));</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">        app.use(keycloak.middleware({</span><br style="font-size:12.8px"><span style="font-size:12.8px">            logout: &#39;/logout&#39;,</span><br style="font-size:12.8px"><span style="font-size:12.8px">            admin: &#39;/&#39;</span><br style="font-size:12.8px"><span style="font-size:12.8px">        }));</span><br style="font-size:12.8px"><span style="font-size:12.8px"> app.get(&#39;/api/user&#39;,* keycloak.protect()*, function (req, res) {</span><br style="font-size:12.8px"><span style="font-size:12.8px">            res.json({</span><br style="font-size:12.8px"><span style="font-size:12.8px">                name: faker.name.findName(),</span><br style="font-size:12.8px"><span style="font-size:12.8px">                email: faker.internet.email(),</span><br style="font-size:12.8px"><span style="font-size:12.8px">                address: faker.address.streetAddress(),</span><br style="font-size:12.8px"><span style="font-size:12.8px">                bio: faker.lorem.sentence(),</span><br style="font-size:12.8px"><span style="font-size:12.8px">                image: faker.image.avatar()</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">  });</span><br style="font-size:12.8px"><span style="font-size:12.8px">        });</span><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">Keycloak.json:</span><br style="font-size:12.8px"><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px">  &quot;realm&quot; : &quot;nodejs-example&quot;,</span><br style="font-size:12.8px"><span style="font-size:12.8px">  &quot;realm-public-key&quot; :</span><br style="font-size:12.8px"><span style="font-size:12.8px">&quot;</span><span style="font-size:12.8px">MIGfMA0GCSqGSIb3DQEBAQUAA4GNA<wbr>D</span><span style="font-size:12.8px">CBiQKBgQCrVrCuTtArbgaZzL1hvh0<wbr>x</span><span style="font-size:12.8px">tL5mc7o0NqPVnYXkLvgcwiC3BjLGw<wbr>1</span><span style="font-size:12.8px">tGEGoJaXDuSaRllobm53JBhjx33UN<wbr>v</span><span style="font-size:12.8px">+5z/</span><span style="font-size:12.8px">UMG4kytBWxheNVKnL6GgqlNab<wbr>MaFfP</span><span style="font-size:12.8px">LPCF8kAgKnsi79NMo+</span><span style="font-size:12.8px">n6KnSY8<wbr>YeUmec/</span><span style="font-size:12.8px">p2vjO2NjsSAVcWEQMVhJ31L<wbr>wIDAQAB</span><span style="font-size:12.8px">&quot;,</span><br style="font-size:12.8px"><span style="font-size:12.8px">  &quot;auth-server-url&quot; : &quot;</span><a href="http://xxxx:9090/auth" rel="noreferrer" style="font-size:12.8px" target="_blank">http://xxxx:9090/auth</a><span style="font-size:12.8px">&quot;,</span><br style="font-size:12.8px"><span style="font-size:12.8px">  &quot;ssl-required&quot; : &quot;external&quot;,</span><br style="font-size:12.8px"><span style="font-size:12.8px">  &quot;resource&quot; : &quot;nodejs-connect&quot;,</span><br style="font-size:12.8px"><span style="font-size:12.8px">  &quot;public-client&quot; : true</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">Thanks,</span><br style="font-size:12.8px"><span style="font-size:12.8px">Deepak</span><br></div>
<br></div></div>______________________________<wbr>_________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailma<wbr>n/listinfo/keycloak-user</a><br></blockquote></div><br></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>