11/**
22 * @file
3- * Example 021 : Phone-based recipient authentication
3+ * Example 020 : Phone authentication
44 * @author DocuSign
55 */
66
@@ -9,8 +9,8 @@ const { phoneAuthentication } = require('../examples/phoneAuthentication');
99const validator = require ( 'validator' ) ;
1010const dsConfig = require ( '../../../config/index.js' ) . config ;
1111
12- const eg021PhoneAuthentication = exports ;
13- const eg = 'eg021 ' ; // This example reference.
12+ const eg020PhoneAuthentication = exports ;
13+ const eg = 'eg020 ' ; // This example reference.
1414const mustAuthenticate = '/ds/mustAuthenticate' ;
1515const minimumBufferMin = 3 ;
1616
@@ -19,7 +19,7 @@ const minimumBufferMin = 3;
1919 * @param {object } req Request obj
2020 * @param {object } res Response obj
2121 */
22- eg021PhoneAuthentication . createController = async ( req , res ) => {
22+ eg020PhoneAuthentication . createController = async ( req , res ) => {
2323 // Step 1: Obtain your OAuth token
2424 // At this point we should have a good token. But we
2525 // double-check here to enable a better UX to the user.
@@ -36,7 +36,8 @@ eg021PhoneAuthentication.createController = async (req, res) => {
3636 const envelopeArgs = {
3737 signerEmail : validator . escape ( body . signerEmail ) , // represents your {SIGNER_EMAIL}
3838 signerName : validator . escape ( body . signerName ) , // represents your {SIGNER_NAME}
39- phoneNumber : validator . escape ( body . phoneNumber )
39+ phoneNumber : validator . escape ( body . phoneNumber ) , // represents your phone number
40+ countryCode : validator . escape ( body . countryCode ) // represents your country code
4041 } ;
4142 const args = {
4243 accessToken : req . user . accessToken , // represents your {ACCESS_TOKEN}
@@ -47,9 +48,10 @@ eg021PhoneAuthentication.createController = async (req, res) => {
4748 let results = null ;
4849
4950 try {
50- // Step 2: Send the envelope
51+ // Step 2: Call the api method
5152 results = await phoneAuthentication ( args ) ;
52- }
53+ console . log ( "WorkflowId: " + results . workflowId ) ;
54+ }
5355 catch ( error ) {
5456 const errorBody = error && error . response && error . response . body ;
5557 // we can pull the DocuSign error code and message from the response body
@@ -59,34 +61,36 @@ eg021PhoneAuthentication.createController = async (req, res) => {
5961 // remediation advice to the user.
6062 res . render ( 'pages/error' , { err : error , errorCode, errorMessage} ) ;
6163 }
64+
6265 if ( results ) {
6366 req . session . envelopeId = results . envelopeId ; // Save for use by other examples
64- // which need an envelopeId
67+ // which need an envelopeId
6568 res . render ( 'pages/example_done' , {
66- title : "Envelope sent " ,
67- h1 : "Envelope sent " ,
69+ title : "Require Phone Authentication for a Recipient " ,
70+ h1 : "Require Phone Authentication for a Recipient " ,
6871 message : `The envelope has been created and sent!<br/>Envelope ID ${ results . envelopeId } .`
6972 } ) ;
7073 }
7174}
7275
76+
77+
7378// ***DS.snippet.0.end
7479
7580/**
7681 * Form page for this application
7782 */
78- eg021PhoneAuthentication . getController = ( req , res ) => {
83+ eg020PhoneAuthentication . getController = ( req , res ) => {
7984 // Check that the authentication token is ok with a long buffer time.
8085 // If needed, now is the best time to ask the user to authenticate
8186 // since they have not yet entered any information into the form.
8287 const tokenOK = req . dsAuth . checkToken ( ) ;
8388 if ( tokenOK ) {
84- sourceFile = ( path . basename ( __filename ) ) [ 5 ] . toLowerCase ( ) + ( path . basename ( __filename ) ) . substr ( 6 ) ;
85- res . render ( 'pages/examples/eg021PhoneAuthentication' , {
89+ res . render ( 'pages/examples/eg020PhoneAuthentication' , {
8690 eg : eg , csrfToken : req . csrfToken ( ) ,
87- title : "Signing request by email " ,
88- sourceFile : sourceFile ,
89- sourceUrl : dsConfig . githubExampleUrl + 'eSignature/examples/ ' + sourceFile ,
91+ title : "Require Phone Authentication for a Recipient " ,
92+ sourceFile : path . basename ( __filename ) ,
93+ sourceUrl : dsConfig . githubExampleUrl + 'eSignature/' + path . basename ( __filename ) ,
9094 documentation : dsConfig . documentation + eg ,
9195 showDoc : dsConfig . documentation
9296 } ) ;
@@ -95,4 +99,4 @@ eg021PhoneAuthentication.getController = (req, res) => {
9599 req . dsAuth . setEg ( req , eg ) ;
96100 res . redirect ( mustAuthenticate ) ;
97101 }
98- }
102+ }
0 commit comments