I have a wordpress based website and use SMS to send users a link containing a key which will allow them to reset their password in wordpress. On a Samsung Android phone the SMS is received by the default Samsung Messages app. The problem is that the app by default (therefore for most of my users) opens the link using a WebView, not the phones full browser, a browser within the Messages app itself. The user enters a new password which my website saves no problem but when it then logs them in using the following standard wordpress code the login fails and the user remains logged out:
wp_set_current_user($user_id, $user->user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login', $user->user_login);
If then I try to manually log in within the webview it will also fail. I'm finding very few resources talking about this issue and I'm unsure how best to solve. I can't find anything that lets you indicate within a url that webview should not be used (not surprisingly but worth a search), or anything even to let me reliably detect the message has been opened in a webview so a 'please copy and paste the sms link' message could be displayed to the user to work around the issue - not ideal but better than them being baffled why they can't log in. ($_SERVER['HTTP_USER_AGENT'] for the webview on a test Samsung phone gives me:
HTTP_USER_AGENT: Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-A510F/A510FXXS8CSF3) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/10.2 Chrome/71.0.3578.99 Mobile Safari/537.36
I assume the issue is being caused because WebView doesn't allow cookies to be stored, thus breaking wordpress login. Can anyone suggest a good way to workaround the issue?