Custom authentication

0 votes

I am building an android app.

I would like to use phone number based authentication for users. I do not want users to enter username, email etc. I could not find a way to do this from the documentation.

Is this usecase possible with the current app42 api ? Can you point me to relevant docs?

 

Thanks,

Rama

asked Mar 28, 2015 in App42 Cloud API-BaaS by coolrama (10 points)

1 Answer

0 votes

Hi,

You can easily achieve this by entering phone number instead of username while creating user , please use the below code snippet :

String phoneNumber = "9896777787";                         

String pwd = "********";  

String emailId = "nick@shephertz.co.in";                      

App42API.initialize("ANDROID_APPLICATION_CONTEXT","API_KEY","SECRET_KEY");  

UserService userService = App42API.buildUserService();   

User user = userService.createUser(phoneNumber, pwd, emailId);    

Profile profile = user.new Profile();  

Date date = new Date();                

profile.setFirstName("Nick");  

profile.setLastName("Gill");  

profile.setSex(UserGender.MALE);  

profile.setDateOfBirth(date);  

profile.setCity("Houston");  

profile.setState("Texas");  

profile.setPincode("74193");  

profile.setCountry("USA");  

profile.setMobile("+1-1111-111-111");  

profile.setHomeLandLine("+1-2222-222-222");  

profile.setOfficeLandLine("+1-33333-333-333");  

userService.createOrUpdateProfile(userObj,new App42CallBack() {  

public void onSuccess(Object response)   

{  

    User user = (User)response;  

    System.out.println("userName is " + user.getUserName());  

    System.out.println("firstName is " + user.getProfile().getFirstName());   

    System.out.println("city is " + user.getProfile().getCity());   

    System.out.println("country is " + user.getProfile().getCountry());   

}  

public void onException(Exception ex)   

{  

    System.out.println("Exception Message"+ex.getMessage());  

}  

}); 

 

and for authenticate purpose you can pass phoneNumber instead of user name, please use below code snippet :

 

String phoneNumber = "9896777787";  

String pwd = "********";     

App42API.initialize("ANDROID_APPLICATION_CONTEXT","API_KEY","SECRET_KEY");  

UserService userService = App42API.buildUserService();   

userService.authenticate(phoneNumber , pwd, new App42CallBack() {  

public void onSuccess(Object response)  

{  

    User user = (User)response;  

    System.out.println("response is " + user);    

}  

public void onException(Exception ex)   

{  

    System.out.println("Exception Message : "+ex.getMessage());  

}  

});  

 

Let me know if it helps

Thanks

/Naresh Dwivedi

 

answered Mar 28, 2015 by naresh (350 points)
I want to ensure that the user is entering the correct phone number using otp verification.

I do not want to enter email id as well. Can email id be optional? Is there a way to generate session tokens and send it to client?
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...