diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 6747a85e0..451dbefb4 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -485,12 +485,23 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); linphone_proxy_config_set_expires(proxyCfg, expire); // setup auth info - LinphoneAddress *from = linphone_address_new(identity); - if (from != 0) { - const char *userid_str = (userID != nil) ? [userID UTF8String] : NULL; - info = linphone_auth_info_new(linphone_address_get_username(from), userid_str, password ? password : NULL, - password ? NULL : ha1, NULL, linphone_proxy_config_get_domain(proxyCfg)); - linphone_address_destroy(from); + if (linphone_core_get_auth_info_list(lc)) { + info = linphone_auth_info_clone(linphone_core_get_auth_info_list(lc)->data); + linphone_auth_info_set_username(info, username.UTF8String); + if (password) { + linphone_auth_info_set_passwd(info, password); + linphone_auth_info_set_ha1(info, NULL); + } + linphone_auth_info_set_domain(info, linphone_proxy_config_get_domain(proxyCfg)); + } else { + LinphoneAddress *from = linphone_address_new(identity); + if (from) { + const char *userid_str = (userID != nil) ? [userID UTF8String] : NULL; + info = linphone_auth_info_new( + linphone_address_get_username(from), userid_str, password ? password : NULL, password ? NULL : ha1, + linphone_proxy_config_get_realm(proxyCfg), linphone_proxy_config_get_domain(proxyCfg)); + linphone_address_destroy(from); + } } // We reached here without hitting the goto: the new settings are correct, so replace the previous ones. diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index d9822dffe..6930db643 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -41,6 +41,8 @@ #import "LinphoneIOSVersion.h" #import +#import "Utils/DTFoundation/DTAlertView.h" +#import "PhoneMainView.h" #define LINPHONE_LOGS_MAX_ENTRY 5000 @@ -884,6 +886,44 @@ static void linphone_iphone_registration_state(LinphoneCore *lc, LinphoneProxyCo [(__bridge LinphoneManager *)linphone_core_get_user_data(lc) onRegister:lc cfg:cfg state:state message:message]; } +#pragma mark - Auth info Function + +static void linphone_iphone_popup_password_request(LinphoneCore *lc, const char *realm, const char *username, + const char *domain) { + // let the wizard handle its own errors + if ([PhoneMainView.instance currentView] != WizardViewController.compositeViewDescription) { + DTAlertView *alertView = [[DTAlertView alloc] + initWithTitle:NSLocalizedString(@"Authentication needed.", nil) + message:[NSString stringWithFormat:NSLocalizedString(@"Registration failed because authentication is " + @"missing or invalid for %s@%s.\nYou can " + @"provide password again, or check your " + @"account configuration in the settings.", + nil), + username, realm]]; + alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; + [alertView addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil]; + __weak UITextField *passwordField = [alertView textFieldAtIndex:0]; + + [alertView addButtonWithTitle:NSLocalizedString(@"Continue", nil) + block:^{ + LinphoneAuthInfo *info = (LinphoneAuthInfo *)linphone_core_find_auth_info( + [LinphoneManager getLc], realm, username, domain); + if (info) { + linphone_auth_info_set_passwd(info, passwordField.text.UTF8String); + linphone_auth_info_set_ha1(info, NULL); + linphone_proxy_config_refresh_register( + linphone_core_get_default_proxy_config([LinphoneManager getLc])); + } else { + LOGE(@"Could not find auth info associated with %s@%s, going to settings!", + username, domain); + [[PhoneMainView instance] + changeCurrentView:[SettingsViewController compositeViewDescription]]; + } + }]; + [alertView show]; + } +} + #pragma mark - Text Received Functions - (void)onMessageReceived:(LinphoneCore *)lc room:(LinphoneChatRoom *)room message:(LinphoneChatMessage *)msg { @@ -1254,7 +1294,7 @@ static LinphoneCoreVTable linphonec_vtable = {.show = NULL, .registration_state_changed = linphone_iphone_registration_state, .notify_presence_received = NULL, .new_subscription_requested = NULL, - .auth_info_requested = NULL, + .auth_info_requested = linphone_iphone_popup_password_request, .display_status = linphone_iphone_display_status, .display_message = linphone_iphone_log_user_info, .display_warning = linphone_iphone_log_user_warning,