The complexity of iOS authentication with google repository using GTMOAuth2

I have been working on this for more than a day, so now I ask for help! I am trying to write an iOS application that authenticates with a google service account to access the Google repository.

I cannot go beyond this error that occurs in authoriseRequest and when trying to create a bucket.

Domain Error = com.google.GTMOAuth2 Code = -1001 "Operation could not be completed. (Com.google.GTMOAuth2 error -1001.)" UserInfo = 0x15640740 {request = {URL: https://www.googleapis.com/ rpc? prettyPrint = false }}

This is my first work with google go-lens libraries and almost all the examples I found on the Internet and on stackOverflow aimed at using GTMOAuth2ViewControllerTouch, but I am not authenticating with the user

So far, I got it.

Until my init ..

static GTLServiceStorage *storageService = nil;
static GTMOAuth2Authentication *auth;

In my init ..

auth = [ GTMOAuth2SignIn standardGoogleAuthenticationForScope:@"kGTLAuthScopeStorageDevstorageFullControl" clientID:@"my_client_id.apps.googleusercontent.com" clientSecret:@"my_client_secret"];
auth.redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
// inititialising the auth token
[auth authorizeRequest:nil  delegate:self didFinishSelector:@selector(authentication:request:finishedWithError:)];

// init googleStorage Backend service.
if (!storageService) {
    storageService = [[GTLServiceStorage alloc] init];
    storageService.additionalHTTPHeaders = @{@"x-goog-project-id": @"my_project_id", @"Content-Type": @"application/json-rpc", @"Accept":
                                                 @"application/json-rpc"};
    storageService.authorizer = auth;
    storageService.retryEnabled = YES;
}

And in a way to create a bucket, for example.

// Create a GTLStorageBucket.
GTLStorageBucket* bucket = [[GTLStorageBucket alloc] init];
bucket.name = @"myBucketName";
// Create the query
GTLQueryStorage *query = [GTLQueryStorage queryForBucketsInsertWithObject:bucket project:@"myGoogleProjectID"];
[storageService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLStorageBucket  *object, NSError *error) {
    NSLog(@"bucket %@", object);
}];

My question is: am I using the gtmoauth2 library correctly to authenticate the service account, and if so, I will miss something obvious in my settings or my initialization.

thank

+4
source share
2 answers

, kGTLAuthScopeStorageDevstorageFullControl , , @ ", NSString, " kGTLAuthScopeStorageDevstorageFullControl", , , , .

0
0

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


All Articles