viana  
                
                  
                    April 7, 2021, 10:34am
                   
                  1 
               
             
            
              I created Parse client App based on REST Guide. And I used Keycloak as auth. I used this doc to do the linking: https://docs.parseplatform.org/rest/guide/#signing-up-and-logging-in . I also used this doc to get authData: https://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication .
But I get error on the server:
Unexpected token u in JSON at position 0
this is my body:
{       "authData": {         "keycloak": {           "access_token": "eyJhbGciOiJSUzI1NiIsInR5...",           "id": "lake",           "roles": [],           "groups": []       	}       }     }
Could anyone help? Please.
             
            
              
           
          
            
            
              Could you share the code for this request which is firing the error?
             
            
              
           
          
            
              
                viana  
                
                  
                    April 8, 2021, 12:44am
                   
                  3 
               
             
            
              I tried post the params using Talend API Tester.
and this is the Parse Server config:
{     "databaseURI": "mongodb://admin:password@db/pserver?authSource=admin",     "appId": "APP_ID",     "masterKey": "MASTER_KEY",     "readOnlyMasterKey": "READ_ONLY_MASTER_KEY",     "restAPIKey": "REST_API_KEY",     "javascriptKey": "JAVASCRIPT_KEY",     "serverURL": "http://localhost:1337/parse",     "publicServerURL": "http://localhost:1337/parse",     "mountGraphQL": true,     "mountPlayground": true,     "auth": {         "keycloak": {           "config": {             "realm": "laker",             "auth-server-url": "http://localhost:8080/auth/",             "ssl-required": "none",             "resource": "lake",             "public-client": true,             "confidential-port": 0           }         }       } }
             
            
              
           
          
            
            
              Where do you see the error?
             
            
              
           
          
            
              
                viana  
                
                  
                    April 9, 2021,  3:11am
                   
                  5 
               
             
            
              In parse-server log (terminal)
             
            
              
           
          
            
            
              It looks the error is coming from this line: parse-server/keycloak.js at master · parse-community/parse-server · GitHub 
Maybe we should log the string in the case it cannot be parsed. Anyways, it looks you are getting some error when trying to authenticate to Keycloak server (which will be hard to debug because of this json parse problem I mentioned before).
Is this address right? “auth-server-url”: “http://localhost:8080/auth/ ”
Maybe you can try to perform this api call and see the error:parse-server/keycloak.js at master · parse-community/parse-server · GitHub 
             
            
              
           
          
            
              
                viana  
              
                  
                    April 10, 2021,  7:17am
                   
                  7 
               
             
            
              Yes the address is correct.
             
            
              
           
          
            
              
                viana  
              
                  
                    April 21, 2021,  8:43am
                   
                  8 
               
             
            
              After trying to solve:
{     host: "keycloak-semarang.sccic.cloudns.asia",     port: 80,     method: 'GET',     path: "/auth/realms/myrealm/protocol/openid-connect/userinfo",     headers: {       Authorization: 'Bearer eyJ...'     }   }
is there any method to do that without manually?
             
            
              
           
          
            
            
              In order to achieve that, I believe you should set your Parse Server config with auth-server-url to keycloak-semarang.sccic.cloudns.asia and realm to myrealm.
             
            
              
           
          
            
              
                viana  
              
                  
                    April 26, 2021,  2:38am
                   
                  10 
               
             
            
              It doesnt work. The problem is in httpRequest, I have tried manually add to the file. The problem is just my Parse server cannot send the request except use manual code (like I wrote before). When I write auth-server-url config using base url, then the path /auth doesnt included.
             
            
              
           
          
            
            
              I didn’t get it. Would you mind to share your current config and what you get?
             
            
              
           
          
            
              
                viana  
              
                  
                    April 27, 2021,  1:12pm
                   
                  12 
               
             
            
              this is the snippet code from lib/Adapters/Auth/httpsRequest.js:
``
// console.log(options);
options = {
host: "keycloak-semarang.sccic.cloudns.asia",
port: 80,
method: 'GET',
path: "/auth/realms/laker/protocol/openid-connect/userinfo",
headers: {
  Authorization: 'Bearer eyJ...'
}
}
return new Promise((resolve, reject) => {
https.get(options, makeCallback(resolve, reject, noJSON)).on('error', reject);
});
}
I replaced default options with my code manually, and it works. But if I remove my code, it doesnt work. even I modify my config like you said before.
             
            
              
           
          
            
            
              Have you tried with with auth-server-url to keycloak-semarang.sccic.cloudns.asia/auth and realm to laker ?
I’m not sure if that’s possible to use keycloak-semarang.sccic.cloudns.asia/auth as a host, but /auth is missing in the beginning of the path.
             
            
              
           
          
            
            
              Hello I’ve exactly the same error.http://localhost:8180/auth/realms/Myrealm/protocol/openid-connect/userinfo 
But when I send a link request to parse server I get this error on parse server console
here’s the requesthttp://localhost:1337/parse/users 
{
 
Please do you have any ideas to solve this issue ?
             
            
              
           
          
            
            
              It looks that the error is coming from this line: parse-server/keycloak.js at alpha · parse-community/parse-server · GitHub 
It is a problem in the code that is avoiding you to see the real error but it probably comes from this request:
const response = await httpsRequest.get({
      host: config['auth-server-url'],
      path: `/realms/${config['realm']}/protocol/openid-connect/userinfo`,
      headers: {
        Authorization: 'Bearer ' + access_token,
      },
    });
Do you have auth-server-url and realm set in your options? Would you mind to share your parse server settings?
             
            
              
           
          
            
            
              ok this is my parse server config
const parseServer = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/test',
  appId: 'APPLICATION_ID',
  masterKey: 'MASTER_KEY',
  serverURL: 'http://localhost:1337/parse',
  publicServerURL: 'http://localhost:1337/parse',
  appName: 'Back',
  auth: {  keycloak: {   config: require(`./auth/keycloak.json`) } }
});
Here’s keycloack.json
{
  "realm": "Myrealm",
  "auth-server-url": "http://localhost:8180/auth/",
  "ssl-required": "external",
  "resource": "backend",
  "public-client": true,
  "confidential-port": 0
}
If I change the realm name in the config it says that the realm doesn’t exist which it make me imagine that’s not realm that cause the issue
             
            
              
           
          
            
            
              I’d try to find this line  of code on node_modules and console.log the error.
             
            
              
           
          
            
            
              e.text is undefined that’s why const error = JSON.parse(e.text); fails
the config is ok i’ve checked the config object.
The error is throw when
const response = await httpsRequest.get({
      host: config['auth-server-url'],
      path: `/realms/${config['realm']}/protocol/openid-connect/userinfo`,
      headers: {
        Authorization: 'Bearer ' + access_token
      }
    });
The exception contains this messagehttp://localhost:8180/auth/ 
same error with keycloak-semarang.sccic.cloudns.asia/auth/Welcome to Keycloak 
EDIT:
             
            
              1 Like