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

GoogleAuthFactor getMostRecentChallenge() bug #580

Description

@mdeggies

I think there is a bug in the GoogleAuthenticatorFactor's getMostRecentChallenge() method. Code to reproduce:

'use strict';

var stormpath = require('stormpath');

var client = new stormpath.Client({
  apiKey : {
    "id": $ID,
    "secret": $SECRET
  }
});

var applicationHref = "https://api.stormpath.com/v1/applications/$APP_ID";
var accountHref = "https://api.stormpath.com/v1/accounts/$ACCT_ID";

client.getApplication(applicationHref, function(err, application){
  client.getAccount(accountHref, function (err, account) {

    var collectionQueryOptions = {
      type: 'google-authenticator'
    };

    var factor = {
      type: 'google-authenticator',
      accountName: '$ACCT_EMAIL_ADDRESS',
      issuer: '$NAME_OF_APP'
    };

   // Create initial factor for account
    account.createFactor(factor, function(err, googleAuthenticatorFactor) {
      if (err) {
        return console.log(err);
      }

      console.log(googleAuthenticatorFactor);
    });

    // Get all google-auth factors for the account
    account.getFactors(collectionQueryOptions, function(err, CollectionResource) {
      if (err) {
        return console.log(err);
      }

      var googleAuthenticatorFactor = CollectionResource.items[0];

      // Create google-auth challenge
      googleAuthenticatorFactor.createChallenge(function(err, createdChallenge) {
        if (err) {
          return console.log(err);
        }
        console.log(createdChallenge);

         // Try to get the most recently created challenge. 
        // This is always returning null for me 
        googleAuthenticatorFactor.getMostRecentChallenge(function(err, challenge){
          if (err) {
            return console.log(err);
          }

          if (challenge === null) {
            return console.log('Challenge has not been created');
          }

          console.log('Most recent challenge:', challenge);
        });
      });
    });
  });
});

EDIT: In REST, mostRecentChallenge() is updated right after a challenge is created. In this SDK, the cached version is being used and never getting updated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions