Skip to content

Commit

Permalink
feat: Add support for FACTOR_ENROLL state. (#196)
Browse files Browse the repository at this point in the history
- Adds support for FACTOR_ENROLL state in auth js.

Resolves: OKTA-215034
  • Loading branch information
nikhilvenkatraman-okta authored Mar 20, 2019
1 parent 1ca7e02 commit dde3dfb
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function link2fn(sdk, res, obj, link, ref) {

var data = addStateToken(res, opts);

if (res.status === 'MFA_ENROLL') {
if (res.status === 'MFA_ENROLL' || res.status === 'FACTOR_ENROLL') {
// Add factorType and provider
util.extend(data, {
factorType: obj.factorType,
Expand Down
109 changes: 109 additions & 0 deletions test/spec/factor-enroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
var util = require('../util/util'),
_ = require('lodash');

describe('FACTOR_ENROLL', function () {
describe('factors', function () {
describe('factor.questions', function () {
util.itMakesCorrectRequestResponse({
setup: {
status: 'factor-enroll',
request: {
method: 'get',
uri: '/api/v1/users/00uoy3CXZHSMMJPHYXXP/factors/questions'
},
response: 'questions'
},
execute: function (test) {
var factor = _.find(test.trans.factors, {
factorType: 'question',
provider: 'OKTA'
});
return factor.questions();
},
expectations: function (test, res) {
expect(test.resReply.status).toEqual(200);
expect(test.responseBody).toEqual(res);
}
});
});

describe('factor.enroll', function () {
util.itMakesCorrectRequestResponse({
title: 'enrolls with updatePhone',
setup: {
status: 'factor-enroll',
request: {
uri: '/api/v1/authn/factors?updatePhone=true',
data: {
stateToken: '01Z20ZhXVrmyR3z8R-m77BvknHyckWCy5vNwEA6huD',
factorType: 'sms',
provider: 'OKTA',
profile: {
phoneNumber: '+1-555-415-1337'
}
}
},
response: 'factor-enroll-activate-sms'
},
execute: function (test) {
var factor = _.find(test.trans.factors, {
factorType: 'sms',
provider: 'OKTA'
});
return factor.enroll({
profile: {
phoneNumber: '+1-555-415-1337',
updatePhone: true
}
});
}
});
util.itMakesCorrectRequestResponse({
setup: {
status: 'factor-enroll',
request: {
uri: '/api/v1/authn/factors',
data: {
stateToken: '01Z20ZhXVrmyR3z8R-m77BvknHyckWCy5vNwEA6huD',
factorType: 'sms',
provider: 'OKTA',
profile: {
phoneNumber: '+1-555-415-1337'
}
}
},
response: 'factor-enroll-activate-sms'
},
execute: function (test) {
var factor = _.find(test.trans.factors, {
factorType: 'sms',
provider: 'OKTA'
});
return factor.enroll({
profile: {
phoneNumber: '+1-555-415-1337'
}
});
}
});
});
});

describe('trans.cancel', function () {
util.itMakesCorrectRequestResponse({
setup: {
status: 'factor-enroll',
request: {
uri: '/api/v1/authn/cancel',
data: {
stateToken: '01Z20ZhXVrmyR3z8R-m77BvknHyckWCy5vNwEA6huD'
}
},
response: 'cancel'
},
execute: function (test) {
return test.trans.cancel();
}
});
});
});
66 changes: 66 additions & 0 deletions test/xhr/factor-enroll-activate-sms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module.exports = {
"status": 200,
"responseType": "json",
"response": {
"stateToken": "01lT7DEzQaeP6mv1_y3pdXjNEONzk83mXX-yhgEdVQ",
"expiresAt": "2014-11-03T00:46:09.700Z",
"status": "FACTOR_ENROLL_ACTIVATE",
"relayState": "/myapp/some/deep/link/i/want/to/return/to",
"_embedded": {
"user": {
"id": "00ub0oNGTSWTBKOLGLNR",
"profile": {
"login": "[email protected]",
"firstName": "Isaac",
"lastName": "Brock",
"locale": "en_US",
"timeZone": "America/Los_Angeles"
}
},
"factor": {
"id": "mbl198rKSEWOSKRIVIFT",
"factorType": "sms",
"provider": "OKTA",
"profile": {
"phoneNumber": "+1 XXX-XXX-1337"
}
}
},
"_links": {
"next": {
"name": "activate",
"href": "<%= uri %>/api/v1/authn/factors/mbl198rKSEWOSKRIVIFT/lifecycle/activate",
"hints": {
"allow": [
"POST"
]
}
},
"cancel": {
"href": "<%= uri %>/api/v1/authn/cancel",
"hints": {
"allow": [
"POST"
]
}
},
"prev": {
"href": "<%= uri %>/api/v1/authn/previous",
"hints": {
"allow": [
"POST"
]
}
},
"resend": [{
"name": "sms",
"href": "<%= uri %>/api/v1/authn/factors/mbl198rKSEWOSKRIVIFT/lifecycle/resend",
"hints": {
"allow": [
"POST"
]
}
}]
}
}
};
119 changes: 119 additions & 0 deletions test/xhr/factor-enroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
module.exports = {
"status": 200,
"responseType": "json",
"response": {
"stateToken": "01Z20ZhXVrmyR3z8R-m77BvknHyckWCy5vNwEA6huD",
"expiresAt": "2014-11-02T23:44:41.736Z",
"status": "FACTOR_ENROLL",
"relayState": "/myapp/some/deep/link/i/want/to/return/to",
"_embedded": {
"user": {
"id": "00ub0oNGTSWTBKOLGLNR",
"profile": {
"login": "[email protected]",
"firstName": "Isaac",
"lastName": "Brock",
"locale": "en_US",
"timeZone": "America/Los_Angeles"
}
},
"factors": [{
"factorType": "question",
"provider": "OKTA",
"_links": {
"questions": {
"href": "<%= uri %>/api/v1/users/00uoy3CXZHSMMJPHYXXP/factors/questions",
"hints": {
"allow": [
"GET"
]
}
},
"enroll": {
"href": "<%= uri %>/api/v1/authn/factors",
"hints": {
"allow": [
"POST"
]
}
}
}
}, {
"factorType": "token",
"provider": "RSA",
"_links": {
"enroll": {
"href": "<%= uri %>/api/v1/authn/factors",
"hints": {
"allow": [
"POST"
]
}
}
}
}, {
"factorType": "token:software:totp",
"provider": "GOOGLE",
"_links": {
"enroll": {
"href": "<%= uri %>/api/v1/authn/factors",
"hints": {
"allow": [
"POST"
]
}
}
}
}, {
"factorType": "token:software:totp",
"provider": "OKTA",
"_links": {
"enroll": {
"href": "<%= uri %>/api/v1/authn/factors",
"hints": {
"allow": [
"POST"
]
}
}
}
}, {
"factorType": "sms",
"provider": "OKTA",
"_links": {
"enroll": {
"href": "<%= uri %>/api/v1/authn/factors",
"hints": {
"allow": [
"POST"
]
}
}
}
}, {
"factorType": "push",
"provider": "OKTA",
"_links": {
"enroll": {
"href": "<%= uri %>/api/v1/authn/factors",
"hints": {
"allow": [
"POST"
]
}
}
}
}]
},
"_links": {
"cancel": {
"href": "<%= uri %>/api/v1/authn/cancel",
"hints": {
"allow": [
"POST"
]
}
}
}
}
};

0 comments on commit dde3dfb

Please sign in to comment.