How can I fix impaired functionality caused by disallowed useragent?

梦想与她 提交于 2019-12-10 12:56:45

问题


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

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];

回答1:


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";
}


来源:https://stackoverflow.com/questions/44344720/how-can-i-fix-impaired-functionality-caused-by-disallowed-useragent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!