I am trying to store the accessToken from an IdP in app_metadata from within an Custom Social Connection. The Profile is being created correctly.
The accessToken is available, as I can use one of the standard Profile fields to store it.
However all my built in Social connections use an app_metadata rule for consistency.
This is my code in Fetch user Profile Script.
function(accessToken, ctx, cb) {
request.get('https://api.pinterest.com/v1/me/', {
headers: {
'Authorization': 'Bearer ' + accessToken
}
}, function(e, r, b) {
if (e) return cb(e);
if (r.statusCode !== 200) return cb(new Error('StatusCode: ' + r.statusCode));
var profile = JSON.parse(b);
profile.app_metadata = profile.app_metadata || {};
profile.app_metadata.oauthToken = accessToken;
cb(null, {
user_id: profile.data.id,
family_name: profile.data.last_name,
given_name: profile.data.first_name,
name: profile.data.first_name + " " + profile.data.last_name
});
});
}
This part was previously suggested on the forum.
profile.app_metadata = profile.app_metadata || {};
profile.app_metadata.oauthToken = accessToken;
But nothing is stored. However…
nickname = accessToken
Stores the accessToken in the Profile.
The documentation, the support forum and support all seem to contradict each other. Maybe there is someone else who can help please ?