-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No notifications were fired ? #26
Comments
Have you used the same name for your service in all the cases? Your example uses "SampleService" and "myFancyService". |
Yes, checked it. Here is the code inside app. delegate .m: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreAccountsDidChangeNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification){ NSLog(@"Success!"); }]; [[NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreDidFailToRequestAccessNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification){ NSError *error = [aNotification.userInfo objectForKey:NXOAuth2AccountStoreErrorKey]; NSLog(@"Failure %@!", [error localDescription]); }]; [[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"SampleService"]; return YES; } + (void)initialize; { [[NXOAuth2AccountStore sharedStore] setClientID:@"123" secret:@"321" authorizationURL:[NSURL URLWithString:@"http://localhost/myapp/authorize.php"] tokenURL:[NSURL URLWithString:@"http://localhost/myapp/token.php"] redirectURL:[NSURL URLWithString:@"http://localhost/myapp/dummy.php"] forAccountType:@"SampleService"]; } When I run app. I observe that app. makes request to http://localhost/myapp/authorize.php with clientid, secret ... receives code and contacts http://localhost/myapp/token.php with grant_type .... and receives back JSON { access_token:".....", scope: "..." } [NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreAccountsDidChangeNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification){ NSLog(@"Success!"); }]; is never executed ? Can you confirm that the code bellow: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreAccountsDidChangeNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification){ NSLog(@"Success!"); }]; [[NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreDidFailToRequestAccessNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification){ NSError *error = [aNotification.userInfo objectForKey:NXOAuth2AccountStoreErrorKey]; NSLog(@"Failure %@!", [error localDescription]); }]; [[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"SampleService"]; return YES; } + (void)initialize; { [[NXOAuth2AccountStore sharedStore] setClientID:@"123" secret:@"321" authorizationURL:[NSURL URLWithString:@"http://localhost/myapp/authorize.php"] tokenURL:[NSURL URLWithString:@"http://localhost/myapp/token.php"] redirectURL:[NSURL URLWithString:@"http://localhost/myapp/dummy.php"] forAccountType:@"SampleService"]; } is enough ?. |
Are you presenting the web page for authenticating in an external browser? If yes, you need to make sure, that the schema of the redirect URL is handled by your app. You have to register that URL while setting the client id/secret etc. (e.g., "mysampleservice://oauth2/"). Either way you have to call [[NXOAuth2AccountStore sharedStore] handleRedirectURL:...].
This part is missing in our documentation (we have to go over it). Tobias. |
Thank you, it works perfectly. First we need to register custom URL scheme for our app. Here is tutorial: http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreAccountsDidChangeNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification){ NSLog(@"Success!"); }]; [[NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreDidFailToRequestAccessNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification){ NSError *error = [aNotification.userInfo objectForKey:NXOAuth2AccountStoreErrorKey]; NSLog(@"Failure %@!", [error localDescription]); }]; [[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"SampleService"]; return YES; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { BOOL handled = [[NXOAuth2AccountStore sharedStore] handleRedirectURL:url]; if (!handled) { NSLog(@"The URL (%@) could not be handled. Maybe you want to do something with it.", [url absoluteString]); } return handled; } + (void)initialize; { [[NXOAuth2AccountStore sharedStore] setClientID:@"123" secret:@"321" authorizationURL:[NSURL URLWithString:@"http://localhost/myapp/authorize.php"] tokenURL:[NSURL URLWithString:@"http://localhost/myapp/token.php"] redirectURL:[NSURL URLWithString:@"sampleservice://oauth2"] forAccountType:@"SampleService"]; } |
I tried to test OAuth2Client with demo project (iPhone), using google-php oauth2 server, configured OAuth2Client and called:
Everything seems to be working fine ... I sniffed web traffic, app. opened webview, I approved access, it completed all oauth2 steps and in last step received code (access_token), which was valid (I tried to use it manually) but no notifications were fired.
NXOAuth2AccountStoreAccountsDidChangeNotification ?
NXOAuth2AccountDidFailToGetAccessTokenNotification ?
Am I missing something or should I parse manually received response from token endpoint to extract access token ?
What I did
I configured client with:
in app delegate,
Called [[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"myFancyService"]; - client did all necessary steps to complete auth. process,
On success I should have received NXOAuth2AccountStoreAccountsDidChangeNotification or NXOAuth2AccountDidFailToGetAccessTokenNotification ...
Everything works but no notifications were fired/received. I need them to close webview and to continue using client for further requests.
Thank you.
The text was updated successfully, but these errors were encountered: