7

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];
Maxim Pavlov
  • 2,962
  • 1
  • 23
  • 33
Vulkan
  • 1,004
  • 16
  • 44

1 Answers1

5

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";
}
Maxim Pavlov
  • 2,962
  • 1
  • 23
  • 33
  • Thank you for your rich response. I was not working all this time sorry for the delay! I changed it to an arbitrary value and t's working fine. – Vulkan Jun 23 '17 at 13:10