Vrankela
Vrankela

Reputation: 1202

Trouble with authenticating a test web app using keyrock

First we set up our app in the fiware lab: enter image description here

the code that we are using to create the app is on this site

The only thing we changed from that link is the config.js:

var config = {}

config.idmURL = 'https://account.lab.fiware.org/';
config.client_id = 'f9b5940d67a741a38039690e4d6e6c6f';
config.client_secret = 'c9f854c96c9e4c70a0d402bce3233a17';
config.callbackURL = 'http://panonit.com:8802/user_info';

// Depending on Grant Type:
// Authorization Code Grant: code
// Implicit Grant: token
config.response_type = 'code';

module.exports = config;

When deploying the node server we have the following site up and running (on a colleagues laptop): the site You can see it for yourself between the hours of 09h and 18h CET.

After we click log in we are properly taken to the fiware site where the user can authenticate: authenticate

And this is where the site breaks (it says page unavailable): page unavailable

To over come this issue we only changed the server.js to output only the response:

// Ask IDM for user info
app.get('/user_info', function(req, res){
    var url = config.idmURL + '/user/';

    // Using the access token asks the IDM for the user info
    oa.get(url, req.session.access_token, function (e, response) {

        //var user = JSON.parse(response);
  var user = response;
  console.log("Getting user response is: " + user)
        //res.send("Welcome " + user.displayName + "<br> Your email address is " + user.email + "<br><br><button onclick='window.location.href=\"/logout\"'>Log out</button>");
  res.send("Welcome " + user)
    });
});

After doing this we have restarted the server. From here we once again pressed the log in and authenticated the app usage and instead of the site break we get: enter image description here

here we have concluded that the response is an empty object because undefined is printed out.

What are we doing wrong here?

Upvotes: 2

Views: 306

Answers (2)

&#193;lvaro Alonso
&#193;lvaro Alonso

Reputation: 385

yes, the issue is what albertinisg has pointed out. The callbackURL must be /login in order to get the code and from it retrieve the access token. Then with the access token you will be able to retrieve the user info.

BR

Upvotes: 0

albertinisg
albertinisg

Reputation: 491

Checking it, the problem is that you are using a wrong callback URL. If you check the server.js, the path for the callback URL you are using is /user_info, and to use that, first you need the req.session.access_token that you retrieve at /login. Just change the callback url for:

config.callbackURL = 'http://panonit.com:8802/login';

And everything should work. Also remember to change it in your IdM app configuration!

Upvotes: 2

Related Questions