I created a custom connection (generic OAuth2 connection), and the profile data is being populated correctly on the user’s first login, but it is not being updated when the user login again.
Here’s Fetch User Profile Script of the custom connection
function(accessToken, ctx, cb) {
request.get({
url: 'https://mycompany.service-now.com/api/current_user ',
headers: {
'Authorization': 'Bearer ' + accessToken
}
}, function(err, resp, body) {
if (err) return cb(err);
if (resp.statusCode !== 200) return cb(new Error(body));
var data = JSON.parse(body);
var profile = data.result;
profile"organization_id"] = "sn_" + profile.instance_id;
profile"tenant_id"] = profile.organization_id;
console.log(JSON.stringify(profile));
cb(null, profile);
});
}
In webtask log I’m seeing the updated profile being fetched from mycompany.service-now.com/api/current_user
. (from console.log call)
This is the profile
JSON object i call the callback with.
{
"name": "Some User",
"username": "someuser@mycompany.com",
"user_id": "...",
"resource_id": "resource_id_new",
"email": "...",
"roles": ],
"instance_name": "...",
"instance_id": "...",
"instance_url": "...",
"organization_id": "...",
"tenant_id": "..."
}
However in my rules if I call console.log(JSON.stringify(user))
I can see that user.resource_id is still the old one (from when they first signed up) -
it hasn’t been updated to resource_id_new
Since the profile
object i return from Get User Profile Script has the updated data, but the user
object in Rules doesn’t have the updated data,
I am quite certain that the user profile isn’t being updated correctly.
Is this a known issue? According to the docs the user profile should be updated everytime the user logs in