Stormpath post registration handler: can't save custom data to Okta account

167 Views Asked by At

After a user registers to my application, an ID is assigned in the local MySQL server, and the same ID is then registered as customData.id inside the corresponding Stormpath account.

This worked before the migration to Okta (using express-stormpath version 3.2.0). After the migration and the update to version 4.0.0 the same code doesn't work anymore, and I can't find a reference or documentation to know what to change. There are no explicit errors, but the customData doesn't appear in the new account under "profile", and results undefined if called.

The relevant postRegistrationHandler:

postRegistrationHandler: function(account, req, res, next) {
    account.getCustomData(function(err, data) {
        if (err) {
            return next(err);
        }
        else {
            var newaccount = {
                email: account.email,
                isgestore: isgestore,
                stormpath_href: account.href,
                dataiscrizione: new Date()
            };
            db.query('SELECT * FROM utenti WHERE email = "'+account.email+'";', function(err,check){
                if(err) throw err;
                if(check==''){
                    res.sendStatus(500);
                } else {
                    db.query('UPDATE utenti SET ? WHERE email = "'+account.email+'";', newaccount, function(err,result){
                        if(err) throw err;
                        data.id = check[0].id;
                        data.save();
                        res.redirect('/regRedirect');
                    });
                }
            });
        }
    });
},

The migration from Stormpath to Okta was successful and the customData were imported correctly. The issue presents only with newly registered accounts.

1

There are 1 best solutions below

1
babadofar On

I have recently migrated an app from Stormpath to Okta myself. Using mostly the Java SDK, but also the express nodejs library. Can't say the transition was frictionless.

Several things come to mind as possible things you could check out: - you are updating the "id" field. That might be a reserved field in Okta. Should it be profile.id? - See if you can use the REST API to update your user. It might be easier to figure out what's wrong by going straight to the API.

First fetch your user.

curl -X GET \
https://<your okta app>.com/api/v1/users/<user id> \
  -H 'accept: application/json' \
  -H 'authorization: SSWS  <your api token>' \
  -H 'content-type: application/json' 

Try to set the properties you want to update, in the profile section

  curl -X POST \
  https://<your okta app>.com/api/v1/users/<user id> \
  -H 'accept: application/json' \
  -H 'authorization: SSWS  <your api token>' \
  -H 'content-type: application/json' \
  -d '{
  "profile": {
        "lastName": "johns",
        "secondEmail": null,
        "mobilePhone": null,
        "emailVerificationStatus": "UNKNOWN",
        "email": "[email protected]",
        "stormpathMigrationRecoveryAnswer": "What is the length of a string",
        "login": "[email protected]",
        "firstName": "chris"
    }
}'

OKTA User API Reference: https://developer.okta.com/docs/api/resources/users.html