Skip to main content

Token Base Authentication

Token base auth is system that customer can register into Diyalog sdk with their application User Info, and can chat between thier application user.

With DiyalogSDK User can register in forground mode as well as background mode. Before authentication user need to init DiyalogSDK as below.

DiyalogEngine.diyalogInstance().Initialize(getApplicationContext());
DiyalogEngine.diyalogInstance().waitForReady();

DOMAIN CUSTOMER USER#

a. Foreground method For customer user registration client need to call below method with necessary information. After successfully register on server it will create session in Diyalog SDK and can start messaging. Using below method if user already created session in Diyalog SDK, then it will directly open that session and user can start messaging.

DiyalogEngine.diyalogInstance().startTokenAuth(dlgToken: “diyalogToken”, deviceID: “DeviceID”, isStartActivityIndicator: “Pass True False”, customerID: “CustomerID”, customerName: "Rane", customerPhone: "234567890", customerEmail: "test@test.com")

context - Activity context dlgToken - Main application server will return Diyalog Token when user will login into main application DeviceId - domain specific device id. this is for domain validation CustId - domain customer id CustName - customer name CustPhone - customer phone number (Optional) CustEmail – customer email address (Optional)

b. Background method When customer user will call background method then it will be register on server and after successfully register, it will create session into sdk. And when user will click on Diyalog chat icon from main application to open sdk, it will directly open that session. user does not wait for register. And In background method if there is any failure then it will pass error message into failure callback.

DiyalogEngine.diyalogInstance().startTokenAuthInBackground(context,dlgToken,deviceId,
customerId,customerName, customerPhone, customerEmail, new TokenAuthResponse() {
@Override
public boolean success() {
Log.e("Auth In Bakground","==>> Success ");
return false;
}
@Override
public String failure(String errorMsg) {
Log.e("Auth In Bakground","==>> Error: "+errorMsg);
return null;
}
}) ;

DOMAIN STAFF USER#

a. Foreground method For staff user registration client need to call below method with necessary information. After successfully register on server it will create session in Diyalog SDK and can start messaging. Using below method if user already created session in Diyalog SDK, then it will directly open that session and user can start messaging.

DiyalogEngine.diyalogInstance().startDomainUserTokenAuth( context, dlgToken, sessionId,
userId,
userName,
userPhone,
userEmail);

context - Activity context dlgToken - Main application server will return Diyalog Token when user will login into main application sessionId – Staff user's sessionId userId - Staff user's UserID UserName - Staff user's UserName userPhone - Staff user's PhoneNumber(Optional) userEmail - Staff user's EmailID (Optional)

b. Background method When staff user will call background method then it will be register on server and after successfully register, it will create session into sdk. And when user will click on Diyalog chat icon from main application to open sdk, it will directly open that session. user does not wait for register. And In background method if there is any failure then it will pass error message into failure callback.

DiyalogEngine.diyalogInstance().startDomainUserTokenAuthInBackground(context, dlgToken, sessionId, userId,
userName, userPhone, userEmail, new TokenAuthResponse() {
@Override
public boolean success() {
Log.e("Auth In Bakground","==>> Success ");
return false;
}
@Override
public String failure(String errorMsg) {
Log.e("Auth In Bakground","==>> Error: "+errorMsg);
return null;
}
}) ;

Get Active sessions#

User can get all sessions list those already registered in diyalog SDK. This method will be use for both Domain customer user and staff user.

ArrayList<AccountVo> sessionList = DiyalogEngine.diyalogInstance().getActiveSessions();

This method will return list of saved session from sdk. It will contain userInfo as below:

  • ApplicationUserID
  • AuthID
  • UserName
  • User Image.

Messaging from specific User#

User can start messaging from specific user. If session already saved into Diyalog SDK then user can start messaging with thier UserID.

DiyalogEngine.diyalogInstance().startMessagingWithUserId(context,customerId);

context - Activity context customerId - domain customer id

This method will be use for both Domain customer user and staff user.

New Document#