Open AppleMonkey opened 11 years ago
Hi,
Is the [NXOAuth2PostBodyStream open] Stream has been reopened after close
console output reproducible? The log is there because NSURLConnection is reopening the body stream (which it shouldn't - "Once a stream is closed, it cannot be reopened.").
The NSURLErrordomain error -1012
error maps to NSURLErrorUserCancelledAuthentication
aka kCFURLErrorUserCancelledAuthentication
. It might be because your server is using https without a properly signed signature.
You can use -setTrustModeHandlerForAccountType:block:
method of NXOauth2AccountStore
to set a trust mode handler which returns NXOAuth2TrustModeAnyCertificate
during development. For production I'd highly recommend setting up a correct trust chain.
I hope this helps you.
first of all thanks for your fast reply,
the console output is reproducible, i didn't succeed even once to make it run normally.
your answer is making a lot of sense, i'll check out your solution and i'll get back to you.
thanks again my friend.
unfortunately it didn't solve the problem, i am getting the same error and same log.
just in case this is the code i am using maybe it will give u an idea about it.
(void)initialize; { [[NXOAuth2AccountStore sharedStore] setClientID:@"client1" secret:@"password" authorizationURL:[NSURL URLWithString:@"https://10.2.165.201:8443/AuthServer/oauth/authorize"] tokenURL:[NSURL URLWithString:@"https://10.2.165.201:8443/AuthServer/oauth/token"] redirectURL:[NSURL URLWithString:@"myapp://"] forAccountType:@"MyService"];
[[NXOAuth2AccountStore sharedStore] setTrustedCertificatesHandlerForAccountType: @"MyService" block:^NSArray (NSString hostname) { return [NSArray arrayWithObject: [NSNumber numberWithInt: NXOAuth2TrustModeAnyCertificate]]; }]; }
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[MOViewController alloc] initWithNibName:@"MOViewController" bundle:nil] autorelease]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible];
[[NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreAccountsDidChangeNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification *aNotification) { NSLog(@"success",nil); NSLog(aNotification.name,nil); }];
[[NSNotificationCenter defaultCenter] addObserverForName:NXOAuth2AccountStoreDidFailToRequestAccessNotification object:[NXOAuth2AccountStore sharedStore] queue:nil usingBlock:^(NSNotification aNotification){ NSLog(@"failed",nil); NSError error = [aNotification.userInfo objectForKey:NXOAuth2AccountStoreErrorKey]; NSLog([error description],nil); }]; [[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"MyService"];
return YES; }
and thanks in advance
i am still having the problem please help guys
Hello AppleMonkey, i guess it is a little bit late, but the following lines of code helped me out!
[[NXOAuth2AccountStore sharedStore] setTrustModeHandlerForAccountType:@"MyService" block:^NXOAuth2TrustMode(NXOAuth2Connection *connection, NSString *hostname) {
return NXOAuth2TrustModeAnyCertificate;
}];
Just add this before you are requesting access.
YOU SHOULD JUST USE THIS AS A DEVELOPMENT WORKAROUND
For security reasons I would strongly advise against doing this. If the certificate of your API server is not signed by a CA included in iOS by default consider pinning the certificate of your server using the API above.
ofc toto. I've updated my comment to avoid misunderstandings.
:+1:
hi there,
i am using the explicit method [[NXOAuth2AccountStore sharedStore] requestAccessToAccountWithType:@"MyService"];
but after i come back from the safari using the redirection url sent from the server your library is analyzing the url to extract the code number
sampleservice://?code=xxxx
when it start trying to contact the server to exchange the this code with a token i get this error
[NXOAuth2PostBodyStream open] Stream has been reopened after close
when i print the error in the notification i get:
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x71a4080 {NSErrorFailingURLKey=https://10.2.165.201:8443/AuthServer/oauth/token, NSErrorFailingURLStringKey=https://10.2.165.201:8443/AuthServer/oauth/token}
any help is appreciated