Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Okta expand apiKeys #624

Open
babadofar opened this issue Aug 2, 2017 · 1 comment
Open

Okta expand apiKeys #624

babadofar opened this issue Aug 2, 2017 · 1 comment

Comments

@babadofar
Copy link

babadofar commented Aug 2, 2017

Hi, I'm trying to migrate a Stormpath application that relied heavily on using api keys, and was relieved to see that you had implemented a solution for this on top of Okta. However, I see a bug when trying to call Account. getApiKeys -> apiKeys are not populated.

Is this something you intend to support going forwards? I find the migrated apikeys now in customdata. In the mean time I will just read them from there.

This can be easily tested using the express-stormpath-sample-project, and initing stormpath like this:

app.use(stormpath.init(app, {
  expand: {
    customData: true,
    apiKeys: true
    
  }
}));

Code breaks here: https://github.com/stormpath/stormpath-sdk-node/blob/1.0.0-rc5/lib/resource/Account.js#L447

@passatgt
Copy link

passatgt commented Aug 2, 2017

Yes, this needs to be patched in the node sdk. In the meantime, this is how i get a user's api keys:

//Get available api key field ids
    var apiKeyFields = Object.keys(req.user.profile).filter(function (key) {
    return key.match(/stormpathApiKey_[0-9]+/);
});

//Return api keys array
var apiKeys = {
    size: 0,
    items: []
};

//Get values based on fields ids
apiKeyFields.forEach(function (key) {

    //Stored in customdata as a single string splitted by :
    apikey = req.user.profile[key].split(':');
    if(apikey[1]) {
        apiKeys.items.push({
            id: apikey[0],
            secret: apikey[1]
        });
        apiKeys.size++;
    }
});

//Return if theres any
if(apiKeys.size>0) {
    return res.status(200).send({status: 'success', code: 'api_keys_found', message: 'Api key found.', data: apiKeys});
} else {
    return res.status(404).send({status: 'fail', code: 'no_api_keys', message: "You don't have api keys"});
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants