Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

oAuth2 authentication page gives me a "Cannot Open Page" error

ANSWERED

Hi,

 

We are migrating our Fitbit API to oAuth2 with Implicit Grant Flow (calling directly from iOS app). Since we cannot embed the authentication page into a UIWebView and SFSafariViewController class only supports iOS 9.0, we are redirecting our users to the default Safari app.

 

However 9 of the 10 times we get a "Cannot Open Page: Safari cannot open the page because the address is invalid" which is quite frustrating. If we run the same authentication url in a desktop browser then it will be fine. (sample url: https://www.fitbit.com/oauth2/authorize?client_id=229CW4&response_type=token&redirect_uri=wokamonFit...)

 

Please advise.

 

Thank you!

Wokamon

 

1.pic.jpg

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

 

@JeremiahFitbit Yes you are right. The Safari is not throwing the error against Fitbit's authentication url but my URL Scheme.

 

After some research, I found this: http://stackoverflow.com/questions/27739442/ios-safari-does-not-recognize-url-schemes-after-user-can...

 

If a user chooses 'Cancel' when Safari responds to the URL Scheme with the 'Open App?' popup, Safari will display 'Cannot Open Page' error if the user access the same URL Scheme. The solution is to reboot Safari.

 

I hope Apple will fix this problem in a future patch 😞

View best answer in original post

Best Answer
0 Votes
9 REPLIES 9

I don't think this is an error related to loading the OAuth 2.0 authorization page, otherwise we'd be getting tons of reports.

 

If you have already authorized the app, you will be immediately redirected to your redirect_uri. I'm guessing the problem is that iOS doesn't recognize your redirect URI.

 

Best Answer

I'm using a URL scheme so that my call back url can redirect users back to the app. Are we allow to do that?

Best Answer
0 Votes

I've just set a http url for my redirect_url and it still gives me the same error. Just to calrify that this error does not happen 100% of the time, and it works perfect when there's no error.

 

Also I'm accessing the API from China, could GFW be a potential reason?

Best Answer
0 Votes

@Wokamon wrote:

I'm using a URL scheme so that my call back url can redirect users back to the app. Are we allow to do that?


Yes, you're allowed to do that. Can you confirm if this error happens when you are redirected away from the authorization page?

Best Answer
0 Votes

@Wokamon wrote:

I've just set a http url for my redirect_url and it still gives me the same error. Just to calrify that this error does not happen 100% of the time, and it works perfect when there's no error.

 

Also I'm accessing the API from China, could GFW be a potential reason?


Related to your other topic, the China GFW may be the problem here, too. If Mobile Safari cannot establish a secure connection to www.fitbit.com, this may be the error that it displays.

Best Answer
0 Votes

 

@JeremiahFitbit Yes you are right. The Safari is not throwing the error against Fitbit's authentication url but my URL Scheme.

 

After some research, I found this: http://stackoverflow.com/questions/27739442/ios-safari-does-not-recognize-url-schemes-after-user-can...

 

If a user chooses 'Cancel' when Safari responds to the URL Scheme with the 'Open App?' popup, Safari will display 'Cannot Open Page' error if the user access the same URL Scheme. The solution is to reboot Safari.

 

I hope Apple will fix this problem in a future patch 😞

Best Answer
0 Votes

Hi. I had the same problem. Once cancelled, it would give that error.

 

What I did was sending an extra parameter with a timestamp, so Safari would not cache it. So after the last param, I added a foo param with the number of milliseconds since midnight January 1, 1970. I use as3, but this should be readable for all developers:

 

var foo:Number = new Date().time; //The number of milliseconds since midnight January 1, 1970

var urlRequest:URLRequest = new URLRequest(url+"&foo="+foo);

 

Where url is the url for oAuth2

Best Answer
0 Votes

This is because you have not properly added redirect_url in info.plist file.
Say you have placed yourBundle.fitbit://  in your Callback URL in fitbit dashboard then
in your application info.plist

add url type  yourBundle.fitbit and in LSApplicationQueriesSchemes add yourBundle.fitbit://

Hope this will work.

Thanks

 

Best Answer
0 Votes

My call back url is https://ng in my fitbit account. So my question is how I can set url schemes for "https://ng" in info.plist of my application. Because safari does not open the application through this link.

Best Answer
0 Votes