can i set "redirect url" dynamically? - box-api

I have two problems -
1) I need to set the redirect url depending on a server i work on, which means that i need to have the ability to change the redirect url dynamically,
is there a way to set the redirect url using the API, and not through the web "www.box.com/developers/..." ?
2) I ran into a weird issue today, my app opens the box.net "login window" which redirects to the specified url when the user logs in, it worked fine until today! but for now the "login window" does nothing when the user logs in, it does not responds.
is there something that was changed?

1) yes you can. In the box applications console, leave the redirect url empty for yor app. Then all is needed is to provide a redirect url at runtime, when you make the authentication (this is something you are probably already doing).
2) I cannot reproduce the issue at this time

Related

Save URL of redirected page

I have "hotspot". Then i connect it - it redirects me to login page.
If i have few opened tabs and click on it during auth - they are redirected to my hotspot application.
How to save url except as a GET param?
Application is complex so hard to track all urls changes and pass old url. And it is not pretty.
Something like window/tab storage.
Maybe is there window indentifier that i can save in local-storage or web-sql?
Window identificator can be saved in window.name. It saved across refreshes and urls changes.

Getting a mismatch uri with google drive api even though uri is set correctly in console

I am trying to run Google Drive API using Google Client V3 in PHP. I have credentials for my locahost site set up, have downloaded the JSON and load the client with those credentials and on my local site everything works fine.
When I move it to the live site and download the JSON for the the project we use on the live site I keep getting a redirect_uri_mismatch. I've checked the console for this project and the redirect uri's are set correctly. I have the following for redirect uri
https://www.awesomestories.com/Google/getClient
https://awesomestories.com/Google/getClient
https://www.awesomestories.com/Google/getClient/
https://awesomestories.com/Google/getClient
I realize this is over kill but I wanted to make sure every possible version was set to eliminate this as the problem. The Google prompt is happening and when the code is returned and I try to to load the code parameter into Google client:
$resp = $client->authenticate($_GET['code']);
I get the following response
array(3) {
["error"]=>
string(21) "redirect_uri_mismatch"
["error_description"]=>
string(11) "Bad Request"
["error_uri"]=>
string(0) ""
}
The url that it is being redirected to is
https://www.awesomestories.com/Google/getClient
Which matches what is set in the console. Also we use this same project's credentials on the site already although we are just using the API key associated with this project not the Oauth2 credentials which GoogleClient is using. So for this project this is the first time we are using the Oauth2 credentials set up in the Google Console. I just can't figure out why the authentication is succeeding on the test site but not on the live site.
Another thing that is strange is that initialization of the client looks like this:
$client = new Google_Client();
$client->setAuthConfigFile(SYSTEM_PATH.'/shared/php/google-api-php-client/client-prod.json');
$client->setAccessType('offline');
$client->setApprovalPrompt("force");
$client->setPrompt("consent");
and on my local site when the google prompt authorization screen comes up it asks to allow offline access, but on the live site it never asks to allow offline access.
If someone could point me to what is going wrong I would really appreciate it.
So I don't know why this worked, but it did. I removed all the redirect uris from my console with the project associated with this, ran my code and at prompt screen got a redirect mismatch uri error as expected, I then re added the redirect uris, copying the one from the error message displayed on the prompt and then ran my code and the call succeeded. The strange thing is that the redirect I copied from the error message was the same that was in there before, because I copied the ones I deleted and compared them so I have no idea why this worked. Also before when I set the Google Client with the redirect uri the prompt screen went through fine without a hitch it was only when trying to load the authorization code sent back from Google prompt screen that the uri mismatch error would show up. I've ran Google prompts before where the redirect uri was set incorrectly on the client and this error appears in the prompt screen, so I'm not positive what was going on here, but it now is working.

Error 404 but not if I click on it

If I go to for example www.example.com(requires log in(I log in)) and it has a list of links.
I click on one of them and it redirects me to a fully working page. But if I copy the url (of the link) and paste it into my browser I will get a 404 message. How is this possible and why?
Does it have something to do with cookies? I have no idea.
Thanks for the help.
There are some server variables for credential and/or in-favorite that are created when you login to a site. You can not expect to view the same facility while you are not logged in.

Why is Chrome calling the autocompleted url before validation?

I'm using an API on my website to send emails to the users and while testing my call I noticed I was receiving the email twice.
So the url looks like "localhost/api/sendEmail" and, at least on Chrome, when I'm on localhost and I start typing "/ap" the url is automatically completed.
And I can see on Fiddler that Chrome (well I think that's him) is actually calling it before I press Enter so the mail is sent, and when I press Enter it is of course sent a second time.
This is not a problem since it won't be directly callable by the end-user, but I was just wondering what is the purpose of this first call ? Is Chrome pre-calling the page to make it faster to load ? Can it cause problems in different situations? Can one prevent Chrome from behaving like this?
Again, not a problem at all, but I'm just wondering.
This is Google's prefetch feature, which loads the page quicker, assuming you execute the auto-completed URL.
You can disable this option in Google Chrome:
Settings > Advanced Settings > Privacy: (uncheck) Prefetch resources..
Update 2019
I came across a similar question on superuser, which I provided an updated answer for.
Disable page load prediction service
chrome://settings/ -> expand Advanced section
Disable NoState Prefetch
chrome://flags -> search for "nostate"

Auth redirect - opening a local HTML document in a new tab in a Firefox extension

I am currently trying to port a Chrome extension to Firefox.
The Chrome extension has a "Login" page, which is opened in a new tab as an HTML document. The HTML document is stored in the local directory with other extension files. The user inputs a URL which should represent a server running our application, where the user will be asked to login. After a successful login, the user is redirected back to the options.html page, which is updated to show the user's preferences.
I would like to duplicate this in the Firefox extension, i.e. I would love to avoid writing anything in XUL to build an options page.
I tried opening a new tab with my HTML page like this:
var url = "chrome://myextension/content/options.html";
var win = Components.classes['#mozilla.org/appshell/window-mediator;1']
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow('navigator:browser');
win.gBrowser.selectedTab = win.gBrowser.addTab(url);
But I don't like this for a few reasons: 1) The navbar in the new tab displays the "chrome:// ..." URL, and 2) it breaks the authentication process. The authentication is done using an OAuth type system, and the current URL is passed into the API so that the user can be redirected back upon successful authentication. The authentication fails with "chrome://" as part of the URL.
Just out of curiosity, I tried hardcoding the URL like this:
http://myextension/content/options.html
And the user is actually successfully authenticated, but then the redirect obviously fails afterward.
The Chrome extension seems to work with no problems or weird hacks. From what I can tell, opening it works like this:
chrome.tabs.create({"url":chrome.extension.getURL("options.html"), "selected":true});
And referencing the URL of the tab later so we can be redirected back to it just works like this:
var options_url = chrome.extension.getURL('options.html');
So, I'm wondering: what is the best way to open a local HTML document in a new tab with a Firefox extension, without using the "chrome://" "protocol"? Is there a similar way to how it can be done with Google Chrome extensions?
UPDATE 23/5/12
So this article says that chrome:// URLs are not accessible from the web, only locally.
http://adblockplus.org/blog/web-pages-accessing-chrome-is-forbidden
I think this could be the reason why my authentication was failing. I'm definitely looking for a way for my extension to display a local HTML file in a window or tab without using chrome://.
UPDATE 07/6/12
Here is my (hopefully temporary) solution:
The user enters the URL of the server running our application. He/she is redirected to the application login page, but instead of passing "chrome://myextension/content/options.html" as the URL to be redirected back to after authentication, I pass a phony URL, i.e. "http://myextension/thisis/madeup.html".
In my extension's overlay.js, I set up an HTTP request listener which listens for the phony URL being requested. When a GET happens for the phony URL, I cancel the request, and open the real, locally stored page at "chrome://myextension/content/options.html".
See the following references:
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIObserver
https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads#HTTP_Observers
If you're trying to do this redirect for an OAuth call you should try using OAuthorizer from Mozilla instead of doing the redirect work yourself. Hope that helps!