Which uri redirect should be used (OAuth 2.0)?

I am registering my application for the Google API console. And I get my client secret, client id and two uris redirects .

//● urn:xxxxxxx:oob //● http://localhostxxxxxx 

Of course, I use these elements and get a token request for google. But when I click the authorization button (for example, “Do you want to allow this application?” Yes), two answers appear.

If I use urnxxxxxx, I get: "The operation could not be completed. (Com.google.HTTPStatus error 404.)".

 //Or If I use http://localhostxxxxxxxxxxxxx and click Yes button, then nothing happens. 

What should I do next? (The following code is for a Google reader.)

 #import "MasterViewController.h" #import "DetailViewController.h" #import "GTMOAuth2Authentication.h" #import "GTMOAuth2ViewControllerTouch.h" #import "GTMOAuth2WindowController.h" static NSString *const kKeychainItemName = @"Greader"; @interface MasterViewController () { NSMutableArray *_objects; } @end @implementation MasterViewController - (IBAction)authentication:signInToGoogle:(id)sender; {} - (GTMOAuth2Authentication * ) authForGoogle { NSString * url_string = @"http://www.google.com/reader/api/"; NSURL * tokenURL = [NSURL URLWithString:url_string]; NSString * redirectURI = @"xxxxoob"; GTMOAuth2Authentication * auth; auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"reader" tokenURL:tokenURL redirectURI:redirectURI clientID:@"xxxxx" clientSecret:@"xxxx"]; auth.scope = @"http://www.google.com/reader/api/"; return auth; } - (void)signInToGoogle { GTMOAuth2Authentication * auth = [self authForGoogle]; NSString* auth_string = @"https://accounts.google.com/o/oauth2/auth"; NSURL * authURL = [NSURL URLWithString:auth_string]; GTMOAuth2ViewControllerTouch * viewController; viewController = [[GTMOAuth2ViewControllerTouch alloc]initWithAuthentication:auth authorizationURL:authURL keychainItemName:kKeychainItemName delegate:self finishedSelector:@selector(viewController:finishedWithAuth:error:)]; [self.navigationController pushViewController:viewController animated:YES]; } 
+4
source share
1 answer

You should learn about oAuth first.

As a rule, the 1st link is an authorization stream - you call it and get the code. The second URL is to get the token using the code obtained from the previous URL.

Explaining exactly how to work with oAuth out of scope here, but you have many places that you can read and study.

+2
source

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


All Articles