5.2 Register without Password

The registerEmployeeWithoutPassword function creates a new employee on Bayun's system with supplied (companyName, companyEmployeeId) combination, and links it to Bayun user account with userId matching the supplied email address (creating one if necessary). All subsequent authentication requests for this employee will require user-credentials matching the supplied security questionsAnswers (or passphrase if set). The function takes the following parameters :

Let's say an employee has email as loginId i.e username@bayunsystems.com.

  • activity : Activity Context.

  • companyName : Unique name of the company/tenant the registering employee belongs to, preferably in domain-name format for consistency, e.g. bayunsystems.com. This assumes that the user is getting access to the corresponding enterprise tenant with the same domain-name managed by their employer. In some cases the email domain of the user could be different from the domain of the tenant this user belongs to e.g. username@customdomain.com registering on a tenant with domain bayunsystems.com as a contractor, or on a generic tenant for individual accounts in a consumer use-case (e.g. tenant domain of gmail.com). In such a case, the domain-name part of the tenant is what should be used as the companyName parameter. Alternatively you can also choose to pass app's own internal companyId/tenantId for the registering employee as a parameter.

  • companyEmployeeId : EmployeeId unique within the company, e.g. username@bayunsystems.com. While just the "username" portion might suffice in some cases, it is preferable to use the full loginId for consistency (especially considering that full loginId has to be anyway used for a contractor or consumer use-case). Alternatively you can also choose to pass app's own internal employeeId that is unique within the specific companyName that was used above.

  • email : Bayun userId for the new user being registered, in the form of User Principal Name (UPN) represented as an email address e.g. username@bayunsystems.com. For a consumer use-case, it can be the email address provided by the user themselves, or one provided/generated by the app. If no email address is available, the app can choose to construct a dummy email by concatenating the user's companyName and companyEmployeeId, e.g. companyEmployeeId+"@"+companyName. dummy-email. This email is not needed for subsequent login requests from the registered employee (as combination of companyName and companyEmployeeId uniquely identify the employee), but the credentials associated with the corresponding userId/email (e.g. security answers) will always be used for authorizing this employee from a new device.

  • isCompanyOwnedEmail : Whether the user email is an enterprise email address owned and controlled by the companyName provided above. Relevant only for enterprise apps that typically allow employees of a company to login via SSO (in such cases, the email and companyEmployeeId will be the same as user’s corporate email-address, and the domain-name of these will also match the domain of the tenant provided as companyName). It should otherwise be set to false by default. If it's a company-owned enterprise email address, then we know that the company owns it, and it can be deleted or reclaimed by the company for potential reassignment to another employee as desired.

  • authorizeEmployeeCallback : Block to be executed if employee public key authorization is pending, returns employeePublicKey.

  • newUserCredentialsCallback : Most developers can just leave it null for default functionality. It is used to set Security Questions & Answers for a new user being created, as well as an optional Passphrase. By default, the SDK uses Dialog to take User’s input to set Security Questions & Answers, Passphrase. Using a non-null callback function here, the developer can optionally provide a custom UI block for taking User’s input, to match with the look-and-feel of the app, instead of relying on the default dialog. If non-null, this block will need to take user input for security questions & answers, passphrase and call setNewUserCredentials method in the SDK. The callback is triggered to take these inputs for a new user being registered on Bayun.

  • securityQuestionsCallback : Most developers can just leave it null for default functionality. It is used for taking answers to Security Questions from an existing Bayun User. By default, the SDK uses Dialog to take User’s input for the answers to Security Questions. The developer can optionally provide a custom UI block for taking User’s input, to match with the look-and-feel of the app, instead of relying on the default dialog. If non-null, this block will need to take user answers to the security questions as an input and call validateSecurityQuestions API method in the SDK. The Security Questions and QuestionIds are returned through data of the callback, in the form of List<SecurityQuestion>.

  • passphraseCallback : Optional block that is called only if passphrase is enabled for an existing Bayun User. Most developers can just leave it null for default functionality. By default, the SDK uses Dialog to take user input for passphrase if it is enabled for the user. However the developer can optionally provide a custom UI block to match with the look-and-feel of the app instead of relying on the default dialog. If non-null, this block will need to take user passphrase as input and call Bayun validatePassphrase API for Passphrase validation.

  • successCallback : Success block to be executed after successful user registration.

  • failureCallback : Failure block to be executed if user registration fails, returns BayunError.

Set New User Credentials

The setNewUserCredentials function takes the following parameters :

  • securityQuestionsAnswers : User is required to provide five Security Questions and their Answers. Questions Answers are in the form of List<SecurityQuestionAnswer>. The developer can either offer a list of Security Questions from their own question-bank to make choosing easier for the user, or they can let each user craft their own questions along-with the answers. Bayun just needs any five questions or prompts for the user to provide their respective answers, which will be cryptographically intermingled together into a single complex key to ensure that independent guessing of any specific answer can’t cause any harm.

  • passphrase : Optional Passphrase provided by the User at the time of account creation. The developer can either set it to null by default, in which case the user will need to use Security Answers for login from a new device. Or alternatively the developer can let the user choose whether to set a passphrase or not, and supply the passphrase if chosen.

  • authorizeEmployeeCallback : Block to be executed if employee public key authorization is pending, returns employeePublicKey.

  • successCallback : Success block to be executed after security questions and answers are set successfully.

  • failureCallback : Failure block to be executed if security questions and answers could not be set, returns BayunError.

Validate Security Questions

Use validateSecurityQuestions function to validate the security questions' answers.

The function takes the following parameters :

  • answers : Security questions' answers of type List<SecurityAnswer>.

  • authorizeEmployeeCallback : Block to be executed if employee public key authorization is pending, returns employeePublicKey.

  • successCallback : Success block to be executed after successful Security Questions' Answers validation.

  • failureCallback : Failure block to be executed if user registration fails, returns BayunError.

Validate Passphrase

Use validatePassphrase function to validate the passphrase.

The function takes the following parameters :

  • passphrase : Passphrase to validate.

  • authorizeEmployeeCallback : Block to be executed if employee public key authorization is pending, returns employeePublicKey.

  • successCallback : Success block to be executed after successful user passphrase validation.

  • failureCallback : Failure block to be executed if user registration fails, returns BayunError.

First account of the Company registered with Bayun is the Security Admin account.

Sample Code

String companyName = "bayunsystems.com"; //company portion from loginId
String companyEmployeeId = "username"; //username portion from loginId
String email = "username@bayunsystems.com"; //loginId 
boolean isCompanyOwnedEmail = false;
Activity activity = this;

Handler.Callback authorizeEmployeeCallback = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
         Log.d(TAG, "Authorization of employeePublicKey is Pending.")
         String employeePublicKey = message.getData().getString("employeePublicKey", "");
         return false;
    }
};

Handler.Callback newUserCredentialsCallback = new Handler.Callback() {
    @Override
    public boolean handleMessage(@NonNull Message msg) {

        //Take User Input for Security Questions and Answers
        //Here securityQuestionsAnswers object is created just for reference
        ArrayList<SecurityQuestionAnswer> securityQuestionsAnswers = new ArrayList<>();
        
        SecurityQuestionAnswer securityQuestionAnswer1 = new SecurityQuestionAnswer("<Question1>","<Answer1>");
        SecurityQuestionAnswer securityQuestionAnswer2 = new SecurityQuestionAnswer("<Question2>","<Answer2>");
        SecurityQuestionAnswer securityQuestionAnswer3 = new SecurityQuestionAnswer("<Question3>","<Answer3>");
        SecurityQuestionAnswer securityQuestionAnswer4 = new SecurityQuestionAnswer("<Question4>","<Answer4>");
        SecurityQuestionAnswer securityQuestionAnswer5 = new SecurityQuestionAnswer("<Question5>","<Answer5>");
        securityQuestionsAnswers.add(securityQuestionAnswer1);
        securityQuestionsAnswers.add(securityQuestionAnswer2);
        securityQuestionsAnswers.add(securityQuestionAnswer3);
        securityQuestionsAnswers.add(securityQuestionAnswer4);
        securityQuestionsAnswers.add(securityQuestionAnswer5);
            
        String passpharse ="<passpharse>"; //User input for optional passphrase
        
        Handler.Callback authorizeEmployeeCallback = new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
             Log.d(TAG, "Authorization of employeePublicKey is Pending.")
             String employeePublicKey = message.getData().getString("employeePublicKey", "");
             return false;
            }
        };

        Handler.Callback successCallback = new Handler.Callback() {
            @Override
            public boolean handleMessage(Message message) {
                Log.d(TAG, "Registered with Bayun successfully.");
                return false;
            }
        };

        Handler.Callback failureCallback = new Handler.Callback() {
            @Override
            public boolean handleMessage(Message message) {
                String error = message.getData().getString("BayunError", "");
                Log.d(TAG, "Bayun registration failed.");     
                return false;
            }
        };

        bayunCore.setNewUserCredentials(securityQuestionsAnswers,
                                        passpharse,
                                        authorizeEmployeeCallback,
                                        successCallback,
                                        failureCallback);
        return false;
    }
};
 
Handler.Callback securityQuestionsCallback = new Handler.Callback() {
        @Override
        public boolean handleMessage(@NonNull Message msg) {
        Bundle bundle = msg.getData();
        
        //securityQuestionsArray is a list of Security Question Objects with questionId, questionText 
        ArrayList<SecurityQuestion> securityQuestionsArray = (ArrayList<SecurityQuestion>)msg.getData().getSerializable("securityQuestions");
        
       //Show custom UI to take user input for the answers.
       //Call validateSecurityQuestions function with the user provided answers.
        ArrayList<SecurityAnswer> answers = new ArrayList<>();

        SecurityAnswer securityAnswer1 = new SecurityAnswer(securityQuestionsArray.get(0).getQuestionId(),"<answer1>".toCharArray());
        SecurityAnswer securityAnswer2 = new SecurityAnswer(securityQuestionsArray.get(1).getQuestionId(),"<answer2>".toCharArray());
        SecurityAnswer securityAnswer3 = new SecurityAnswer(securityQuestionsArray.get(2).getQuestionId(),"<answer3>".toCharArray());
        SecurityAnswer securityAnswer4 = new SecurityAnswer(securityQuestionsArray.get(3).getQuestionId(),"<answer4>".toCharArray());
        SecurityAnswer securityAnswer5 = new SecurityAnswer(securityQuestionsArray.get(4).getQuestionId(),"<answer5>".toCharArray());
        answers.add(securityAnswer1);
        answers.add(securityAnswer2);
        answers.add(securityAnswer3);
        answers.add(securityAnswer4);
        answers.add(securityAnswer5);
        
        
        Handler.Callback authorizeEmployeeCallback = new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
             Log.d(TAG, "Authorization of employeePublicKey is Pending.")
             String employeePublicKey = message.getData().getString("employeePublicKey", "");
             return false;
            }
        };

        Handler.Callback successCallback = new Handler.Callback() {
            @Override
            public boolean handleMessage(Message message) {
                Log.d(TAG, "Registered with Bayun successfully.");
                return false;
            }
        };

        Handler.Callback failureCallback = new Handler.Callback() {
            @Override
            public boolean handleMessage(Message message) {
                String error = message.getData().getString("BayunError", "");
                Log.d(TAG, "One or more answers are incorrect.");     
                return false;
            }
        };        

        bayunCore.validateSecurityQuestions(answers, authorizeEmployeeCallback, successCallback, failureCallback);
        return false;
     }
};
                               
Handler.Callback passphraseCallback = new Handler.Callback() {
        @Override
        public boolean handleMessage(@NonNull Message msg) {
        //Show custom UI to take user input for the passphrase.
        String passpharse ="<passpharse>";
        
        Handler.Callback authorizeEmployeeCallback = new Handler.Callback() {
        @Override
            public boolean handleMessage(Message message) {
                Log.d(TAG, "Authorization of employeePublicKey is Pending.")
                String employeePublicKey = message.getData().getString("employeePublicKey", "");
                return false;
                }
        };

        Handler.Callback successCallback = new Handler.Callback() {
            @Override
            public boolean handleMessage(Message message) {
                Log.d(TAG, "Passphrase is validated and registered with Bayun successfully.");
                return false;
            }
        };

        Handler.Callback failureCallback = new Handler.Callback() {
            @Override
            public boolean handleMessage(Message message) {
                String error = message.getData().getString("BayunError", "");
                Log.d(TAG, "Passphrase validation failed with error.");     
                return false;
            }
        };
        //Call validatePassphrase function with the user provided passphrase.
        bayunCore.validatePassphrase(passpharse, authorizeEmployeeCallback, successCallback, failureCallback);
            return false;
        }
 };
    
Handler.Callback successCallback = new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            Log.d(TAG, "Registered with Bayun successfully.");
            return false;
        }
 };

Handler.Callback failureCallback = new Handler.Callback() {
        @Override
        public boolean handleMessage(Message message) {
            String error = message.getData().getString("BayunError", "");
            Log.d(TAG, "Employee registration failed.");     
            return false;
        }
 };

bayunCore.registerEmployeeWithoutPassword(
                        activity,
                        companyName,
                        companyEmployeeId,
                        email,
                        isCompanyOwnedEmail,
                        authorizeEmployeeCallback,
                        newUserCredentialsCallback,
                        securityQuestionsCallback,
                        passphraseCallback,
                        successCallback,
                        failureCallback
                );

Last updated