Javascript XMLHttpRequest Login Promp - javascript

I am new to javascript and wrote a simple extension to parse the gmail atom feed and display the number of unread emails.
My problem is if for some reason you're not logged into your google account, the extension attempts to check the feed and Safari will display a login box like this.
alt text http://img576.imageshack.us/img576/743/loginhd.png
And since I check every 10 seconds these prompts stack up and hijack the browser to the point where you can't go login. Also loggin via this prompt seems to do nothing.
Is there anyway to ignore failed attempts to read the feed? My request looks like this:
xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', url, true);
xmlHttp.onreadystatechange = checkForNewMessagesCallBack;
xmlHttp.send(null);

I do not see it as a failed attempt so you can ignore it .. more like in progress and you are asked for info so that it can complete..
If this is for personal use you could use the https://username:password#URL
The security risks of that method are of course obvious ..

Related

How to allow my google script to be run by anyone off of a webpage

I am currently attempting to write a google script that will run once a submit button is clicked on a form in a webpage. When the button is pressed it takes the form data, logs it into googles Logger and then emails a JSON report from the google account the script was made on. I have just gotten this script to run and print how I want it to thanks to another user on this site and I have now run into the issue that the only reason it was running and working is because I was signed into google on the account I made to send the emails. I have turned my script to public access by anyone on the web and still all I am getting is that google is "unable to open the page at this time." Is there some other way to get around this without having the user use their own email client?
var TO_ADDRESS = "test#email.com";
var output = HtmlService.createHtmlOutputFromFile('Confirmation');
function doPost(e) {
try{
Logger.log(e);
MailApp.sendEmail(T0_ADDRESS, "RFQ: The following person has requested a quote", JSON.stringify(e.parameters, null, 4));
return output;
This is the code which as I said earlier does work as long as I'm logged in but I would like this to be able to be used by anyone that accesses the website
I have done something similar using "Deploy as web app" option you will get an url , you can give that to anyone and they too can execute this without any need of authorization.Below is a walkthrough
You can use this url in whatever way you like, as a curl request,ajax or just a browser url request
But note that you must have a doGet() otherwise it would give an error like in the final screenshot.But since i had put doGet() it ran perfectly (forgot to take its screen :P) .

Chrome Extension OAUTH with Spotify API

I've been writing a chrome extension using the Spotify API and just got to the part where I need OAUTH to finish it up.
I've been looking at the spotify oath page (https://developer.spotify.com/web-api/authorization-guide/)
and it says you can just make a GET call and it'll take you to the page to log in, however when I implement it, it does nothing. I feel like I am missing some code but I am not sure what I am missing.
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
// Just alerting it to see what it came up with
alert(xhr.responseText);
}
}
xhr.open("GET", "https://accounts.spotify.com/authorize/?client_id=<clientID>&response_type=code&redirect_uri=https%3A%2F%2Fwww.google.com%2F", true);
xhr.send();
that is the code I have now (with client id filled in), and running it does nothing. (I specified http://www.google.com/ as my callback for now)
An XHR request will not, under any circumstance, open a page.
Running this code should return you the page contents, but you do nothing with it - certainly not properly display it for the user to interact with.
It seems like you need to read more on OAuth in general. That said:
Chrome extension API provides a specific tool for this: chrome.identity.launchWebAuthFlow(). It will take care of showing the auth page to the user and passing the token back to you. You need to use a specific "virtual" URL for it - see the chrome.identity documentation for more details. Also note that this API can't be used in a content script, you'll need to delegate this to the background page.

Importing events from MS Office 365 (PHP)

I have an intranet site for a small medical clinic, and on the front page I want to display upcoming events associated with the clinic-wide MS Office 365 email account.
I'm new to APIs, so some resources on how to get started would help.
The site is in PHP, but as I understand it, API functions can be done in JavaScript - either way is fine.
Once I can get an XML or JSON file from Microsoft, I'm pretty sure I can figure out how to format it for the site. The problem is just getting the info.
So far I have:
<script>
var req = new XMLHttpRequest();
req.open("GET", "https://outlook.office365.com/api/v1.0/users/{email address}/events", false);
req.send();
console.log(req.status);
console.log(req.StatusText);
</script>
The console logged:
"NetworkError: 401 Anonymous Request Disallowed
I've also tried the line req.open("GET", "https://outlook.office365.com/api/v1.0/users/me/events", false{or true}/ {username}, {password});, to which the console logged
NS_ERROR_DOM_BAD_URI: Access to restricted URI denied
Almost all the documentation I can find is directed toward individual users (employees of a company) interfacing with their 365 accounts through some web-based interface, so almost all of the urls have /me/ in them, indicating they have authenticated somehow. But I want my PHP or JavaScript script to automatically authenticate a single user and retrieve information. I imagine this requires hard-coding the user and password somewhere, but I've found no examples like that.
I'm obviously in way over my head, but can anyone offer any advice on how I can get this done? Or read more about how APIs work? Most of the documentation out there is directed at people who already have a certain level of knowledge, which I don't have, and don't really know how to get.
Thanks.
Missing part is authentication (OAuth) to connect from your app to O365..
Maybe this helps http://msdn.microsoft.com/library/bde5647a-fff1-4b51-b67b-2139de79ce4a%28Office.15%29.aspx
Yes, you do need to authenticate against the Office 365 APIs as indicated previously. To make calls against Office 365, you must register your app for OAuth against Azure AD.
I'd suggest looking at http://dev.office.com/getting-started/office365apis. It should guide you through setting up authentication and show you how to make the rest call.

Communicating between client and server

If I were to build an app where a user could put javascript code on their website and, for example, it would track the number of impressions the site got, what would be the best way to send the information to my server?
XHR / XMLHttpRequest
The verb is probably best implemented as POST here.
MDN API link is the best I can give since it's a vague scenario:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
Here is a small function to send an XMLHttpRequest:
function sendXMLRequest()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://myserver.com", true);
xmlhttp.send();
}
(adapted from http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp)
You would also have to find some way of calling this function when the site gets an 'impression' (or whatever event you want to track).
I would recommend using a web bug/pixel tracking. This makes a GET request to the server. This request wont be blocked by the same origin policy. The big analytics companies all use web bugs. Omniture and Google Analytics.
Basically you do a fake image request and put some extra tracking data on the call.
var webBug = new Image();
webBug.src = "http://yourserver.com/tracking/?visitorId=abc123&sessionId=123abc"
or just put the image into the html,
<img src="http://yourserver.com/tracking/?visitorId=abc123&sessionId=123abc"/>
http://en.wikipedia.org/wiki/Web_bug

Error on ActiveXObject("ADSystemInfo")

I have this line on my JavaScript
var objSysInfo=new ActiveXObject("ADSystemInfo");
var objUser=GetObject("LDAP://" + objSysInfo.UserName);
alert(objUser.displayName);
When I am logged in as an admin everything works fine, but if I am logged in as a non-admin account it starts to give exception on
var objSysInfo=new ActiveXObject("ADSystemInfo");
what seems to be the problem here and how will I solve it?
Are there any other alternatives to get the User Info from javascript, I just want to get the display name? (I know this wont work on FF and Chrome)
BTW this is the error I Get "automation server can't create object active x"
The error indicates that the browser security settings of the current user probably don't permit the instantiation of that particular ActiveX control. Unless you can change the browser security settings of the user, there's really nothing you can do about it programmatically (using JavaScript).
You don't get the same error as an admin user probably because of more lax security settings.
Try playing around with the ActiveX security settings in Internet Options and see if you can get it to work with the non-admin user. Maybe the solution for your end users is to provide documentation on how to change the ActiveX security settings.
I know that this question was asked a few years ago. However, i am answering just in case someone might need this information:
You might want to use something more like this:
**JavaScript**
var wshshell = new ActiveXObject("wscript.shell");
var userName = wshshell.ExpandEnvironmentStrings("%username%");
alert(userName);
**VBScript**
Set ObjSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
Dim userName = objUser.SAMAccountName
'In this case, username will be populated with whatever the AD requires for
'authentication when logging in
Maybe that'll work for you??

Categories

Resources