nxtbgthng / OAuth2Client

Client library for OAuth2 (currently built against draft 10 of the OAuth2 spec)
855 stars 217 forks source link

can't exchange the code with a token #57

Open AppleMonkey opened 11 years ago

AppleMonkey commented 11 years ago

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

stigi commented 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.

AppleMonkey commented 11 years ago

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.

AppleMonkey commented 11 years ago

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.

and thanks in advance

AppleMonkey commented 11 years ago

i am still having the problem please help guys

zvaehn commented 10 years ago

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

toto commented 10 years ago

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.

zvaehn commented 10 years ago

ofc toto. I've updated my comment to avoid misunderstandings.

toto commented 10 years ago

:+1: