Hello! My team and I are currently in the process of trying to implement MFA on our React Native app. We were told that the current okta-react-native SDK doesn’t support MFA, so we were advised (from Okta) to use the okta-auth-js library to accomplish what we need to. We were given a code snippet of how to get tokens after successfully validating an MFA factor. Here is the code snippet -
var transaction = await getAuthClient().signInWithCredentials({ username, password });
const { status, sessionToken } = transaction;
console.log('status: ’ + status + ', sessionToken: ’ + sessionToken);
if (status === ‘MFA_REQUIRED’) {
console.log(transaction.factors);
//check for question
var questionFactor = transaction.factors.find(function(factor) {
return factor.provider === ‘OKTA’ && factor.factorType === ‘question’;
});
if (questionFactor) {
console.log(questionFactor);
var verifyResult = await questionFactor.verify({answer: ‘none’});
console.log('factor verify result: ’ + verifyResult.status + ’ ’ + verifyResult.sessionToken);
var tokens = await authenticate({ sessionToken: verifyResult.sessionToken });
console.log('tokens: ’ + tokens);
this.setState({
progress: false,
username: ‘’,
password: ‘’,
error: ‘’
}, () => navigation.navigate(‘Profile’));
}
} else if (status === ‘SUCCESS’) {
console.log(‘try to get tokens’);
var tokens = await authenticate({ sessionToken });
console.log(tokens);
this.setState({
progress: false,
username: ‘’,
password: ‘’,
error: ‘’
}, () => navigation.navigate(‘Profile’));
}
The only problem is there is no function called “authenticate” unless it’s referring to the object within the idx object of a given authClient (i.e. OktaAuth instance). I try to pass a session token right to this authenticate method, but it’s not working. I’d love to get some insight of what to do, what I am calling, etc… I am getting a sessionToken, but my main goal is to get an accessToken with that sessionToken. Let me know if I need to clarify anything.
Thanks!