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

     if let err = error {
          print("BrandMessenger login failed with an error: ", err.localizedDescription)
          return
     }
     
     print("BrandMessenger login successful")
}
[BrandMessengerManager login:@"accessToken" completion:^(KBMRegistrationResponse * _Nullable response, NSError * _Nullable error) {
        
    if (error != nil) {
        NSLog(@"BrandMessenger login failed with an error: %@", error.localizedDescription);
        return;
    }
        
    NSLog(@"BrandMessenger login successful");
}];

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.isAuthenticated { response in
    if (response) {
        // user is authenticated
    }
}];
[BrandMessengerManager isAuthenticatedWithCompletion:^(BOOL authenticated){
  if (authenticated) {
        // 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)
...
func onRefreshFail(_completion: @escaping (String) -> Void){
completion(<access_token>)
}
[BrandMessenger setAuthenticationDelegate:self];
...
  -(void)onRefreshFail:(void (^)(NSString* accessToken))completion (@ "<accesstoken>" );
}

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

13321332

Did this page help you?