How to fix "403 - disallowed_useragent" using Google Drive’s own SDK?

I follow the instructions at: https://developers.google.com/drive/ios/quickstart?ver=swift .

He worked yesterday, but this morning he always fails. The strange part is that I am using my native SDK. I do not know why I believe that I am using a web view. Exact error:

This user agent does not allow OAuth authorization requests from Google because it is classified as an embedded user agent (also known as web browsing). In accordance with our policy, only the browser is allowed to allow authorization requests to Google. We offer several libraries and samples for our own applications to fulfill the authorization request in the browser.

I cloned: https://github.com/googledrive/ios-quickeditor and got the same error.

+5
source share
4 answers

EDIT: the comment below still applies. I started working again in Swift, and here is the result and what I did (on Github) . Hope this saves someone else on the day of work to figure it out.


Here is the unsuccessful answer: Yes, you are using an example from Google iOS Quickstart , the “native SDK” as you call it. This is deprecated, however, since it uses a precisely built-in webview that Google no longer wants to use.

If this worked before, but suddenly stopped (as I experienced myself), you may need to change something related to the client ID. For customer IDs that have existed for some time, it seems that there is a longer grace period until Google blocks the use of the web view (in my opinion, there should only be some kind of warning). The new client identifier that I recently created for unrelated reasons seems to have caused just that, making me stuck in replacing the Google Drive authentication code for the new release in a short time.

As for the options (that so far only another responder has listed your question from a Google blog post), after a little research, GTMAppAuth seems to be the most viable option for me, since I'm not interested in full user login and logout. But I may be wrong.

GTMAppAuth contains sample code for iOS, but only in Objective-C. I have yet to go through this. In general, your code logic will change this way: your current solution makes authentication exclusively in your application. It is asynchronous, but does not leave your application. The new solution requires that you initiate authentication in your application when preparing and remembering callback functions. Initiation of authentication then opens an external browser, which, after execution, calls the URL callback in the application delegate. In your application’s sharelet, you then check your prepared callback and, depending on the state of the result of the external call, notify the user of the success or failure of external authentication.

+1
source

try this, it will work "Mozilla / 5.0 (Windows NT 6.1) AppleWebKit / 537.36 (KHTML, e.g. Gecko) Chrome / 41.0.2228.0 Safari / 537.36"

Google restricts authentication from web views. it accepts a safari webakit useragent.override useragent with the above user string, it will work.

+1
source

Add this code to your AppDelegate.m (assuming it is in ObjC):

 NSString *userAgent = @"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602"; // set default user agent NSDictionary *dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:userAgent,@"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:(dictionary)]; 
0
source

You can solve this problem using the third-party CloudRail SDK, which is great for Google Drive and the new authentication restrictions. This guide shows you exactly how to use an external browser, not web browsing.

-2
source

Source: https://habr.com/ru/post/1259748/


All Articles