Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix impaired functionality caused by disallowed useragent?

I'm building a web browser an recently I came across an error while trying to login using my Google account on a website.

Screenshot

This is strange because I checked the user agent of my app and Safari's and they are both identical.

Any suggestions?

UPDATE

The WKWebView is nested 3 levels deep inside a tree of custom UIViews.

Here's the initialization code:

_webView = [[WKWebView alloc] init];
_webView.allowsBackForwardNavigationGestures = NO;
_webView.allowsLinkPreview = NO;
_webView.navigationDelegate = self;
_webView.UIDelegate = self;
_webView.frame = CGRectMake(0.0, 0.0, self.contentView.frame.size.width, self.contentView.frame.size.height);
[self.contentView addSubview:_webView];
like image 523
Vulkan Avatar asked Jun 03 '17 14:06

Vulkan


People also ask

How do I fix a disallowed user agent?

Please go to the Google Play Store, download Chrome (it must be Chrome), set Chrome as the default browser, and attempt to add the account again. This will allow you to proceed without issue. If you have further questions, we are available to help at Settings > Help & Feedback > Contact Support.


1 Answers

From Google Modernizing OAuth interactions in Native Apps for Better Usability and Security article:

On April 20, 2017, we will start blocking OAuth requests using web-views for all OAuth clients on platforms where viable alternatives exist.

So, Google now allows sign-in with Google Account only in normal browsers, it restricts it in web-views due to security reasons and recommends Google SDKs for iOS and Android for this purpose.

But if you still want to use WKWebView you may do a little trick, suggested in this answer, setting customUserAgent so it can pass validation:

// Check for selector availability, as it is available only on iOS 9+
if ([_webView respondsToSelector:@selector(setCustomUserAgent:)]) {
    _webView.customUserAgent = @"MyCustomUserAgent";
}
like image 141
Maxim Pavlov Avatar answered Sep 28 '22 14:09

Maxim Pavlov