Authentication and Authorization in iOS (APAC)
Learn more about authentication in our Brand Messenger iOS SDK
Register/Login the User
Optional region setting
The SDK will authenticate with Khoros Auth Handler endpoint during login. Depending on the region, the customer can set the region. Options are KBM_REGION_US or KBM_REGION_APAC. Default is KBM_REGION_APAC when not set.
BrandMessengerManager.setRegion(KBM_REGION_US);
[BrandMessengerManager setRegion:KBM_REGION_US];
The process of logging in a user is a simple, one-step process for Brand Messenger SDK:
BrandMessengerManager.login("accessToken") { response, error in }
[BrandMessengerManager login:@"accessToken" completion:^(KBMRegistrationResponse * _Nullable, NSError * _Nullable) {
}];
Verifying that a user is connected
To check if the user is still authenticated. This will check if jwt is valid, and attempt to refresh jwt if it's expired. If KBMAuthenticationDelegate is set, it will call delegate on refresh fail.
[BrandMessengerManager isAuthenticatedWithCompletion:^(BOOL authenticated) {
if (authenticated) {
// user is authenticated
}
}];
BrandMessengerManager.isAuthenticated { response in
if (response) {
// user is authenticated
}
}
Authentication Delegate
When the auth token expires and SDK's refresh/token API fails, the sdk offers a way to re-establish login auth during operation via a delegate object.
[BrandMessengerManager setAuthenticationDelegate:self];
...
-(void)onRefreshFail:(void (^)(NSString* accessToken))completion {
completion(@"<accesstoken>");
}
BrandMessengerManager.setAuthenticationDelegate(self)
...
func onRefreshFail(_ completion: @escaping (String) -> Void) {
completion(<accesstoken>)
}
Update User Details
Use this API to update the user details after the user has been registered.
Example
In the method below, we are updating imageLinkFromServer and other parameters will be nil. You will need to pass the nil in events in which you do not want to make an update.
KBMUserService *userService = [KBMUserService new];
[userService updateUserDisplayName:@"DISPLAY-NAME" andUserImage:@"PROFILE-IMAGE-URL-LINK" userStatus:nil withCompletion:^(id json, NSError *error) {
if (error) {
NSLog(@"Failed to update the user details %@", error.localizedDescription);
return;
}
}];
let userService = KBMUserService()
userService.updateUserDisplayName("DISPLAY-NAME", andUserImage: "PROFILE-IMAGE-URL-LINK", userStatus: nil) { (response, error) in
if error == nil {
// success
}
}
Get the userId of a currently logged-in BrandMessenger user
Use the below setting to get the currently logged-in user's userId in Brand Messenger.
[KBMUserDefaultsHandler getUserId];
KBMUserDefaultsHandler.getUserId()
Auth flow using Customer's iDP


Updated about 1 month ago