Problem with authentication from actionscript to siteminder SSO - actionscript-3

I am migrating an adobe flex application from web version (running in flash player) to adobe air desktop application.
My application communicate with a "blazeDS service" via remote object (a way pair adobe flex with java backend) at URL: http://myhost.example.com/mycontext/messagebroker/amf
The above URL is protected with CA site minder, if user has not logged in, the system redirect to siteminder log in page at: http://myhost.example.com/sso/*...
I tried send post request to siteMinder service via post man to login success.(Post user name, password, pin, etc..) Then siteminder responsed with the cookies.
My task is try to send http request via action script to login from my air application.
I wrote a simple air application send request when initialize as bellow:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.net.*;
function init(){
var req : URLRequest= new URLRequest("http://myhost.example.com/sso/");//The Siteminder service URL.
var formData : URLVariables = new URLVariables("email=test&uname=1002102571&pass=test&gender=male"); //Post data
req.data = formData;
req.contentType = "application/x-www-form-urlencoded";
req.method = "POST";
var urlLoader : URLLoader = new URLLoader(req);
urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onResponse);
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.load(req);
}
function onResponse(event){
Alert.show("aaa" + event.target);
}
function onComplete(event){
Alert.show("bbb");
}
function response(event){
Alert.show("â0");
}
function fault(event){
Alert.show("nb");
}
]]>
</mx:Script>
</mx:WindowedApplication>
Then siteminder response cookies too.
But when I intergrate my code to the real system, site minder respond log in fail. I don't know what is differrent between two application. Please share your advice.

Related

API Request with adobe AIR

I am trying to consume delicious api in adobe AIR AS3 project described here: https://github.com/avos/delicious-api
particularly the suggest api (/v1/posts/suggest) described at the end of this page: https://github.com/avos/delicious-api/blob/master/api/posts.md
In debug mode the app asks for username and password and keeps asking it even after providing valid username and password and never tracing the response. I have no idea what's going wrong here. Below is my code:
var request:URLRequest = new URLRequest("https://api.del.icio.us/v1/posts/suggest?red=api&url=http%3A%2F%2Fyahoo.com");
request.method = URLRequestMethod.POST;
//encoded string using as3 class at https://github.com/MoritzStefaner/revisit/blob/master/lib/com/hurlant/util/Base64.as
var encoded:String = Base64.encode("validusername:validpassword");
trace(encoded);
var credsHeader:URLRequestHeader = new URLRequestHeader("Authorization", "Basic " + encoded);
request.requestHeaders.push(credsHeader);
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, handleResults);
loader.load(request);
function handleResults(evt:Event):void
{
var response:String = evt.target.data as String;
trace("response:" + response);
}
From taking a brief look at the linked API, none of the methods suggest support for authentication information being sent as part of the POST body (which is what your code is doing). So unless that is documented somewhere else, you are using the API incorrectly. It's also reasonably rare to see an HTTP POST combined with a QueryString (which is again what your code above is doing) so that is a little odd.
I think Delicious just needs HTTP Basic auth, which is covered in an SO question here.

Getting WP8 web requests to be synchronous

I am trying to port some code from a Windows form application to WP8, and have run into some issues regarding asynchronous calls.
The basic idea is to do some UAG authentication. In the Windows form code, I do a GET on the portal homepage and wait for the cookies. I then pass these cookies into a POST request to the validation URL the UAG server. It all works fine in the form, since all the steps are sequential and synchronous.
Now, when I started porting this to WP8, first thing I noticed was that GetResponse() wasn't available, instead I had to use BeginGetResponse(), which is asynchronous and calls a callback function. This is no good for me, since I need to ensure this step finishes before I do the POST
My Windows form code looks like this (taken from http://usingnat.net/sharepoint/2011/2/23/how-to-programmatically-authenticate-to-uag-protected-sharep.html):
private void Connect()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Url);
request.CookieContainer = new CookieContainer();
request.UserAgent = this.UserAgent;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
//Get the UAG generated cookies from the response
this.Cookies = response.Cookies;
}
}
private void ValidateCredentials()
{
//Some code to construct the headers goes here...
HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(this.ValidationUrl);
postRequest.ContentType = "application/x-www-form-urlencoded";
postRequest.CookieContainer = new CookieContainer();
foreach (Cookie cookie in this.Cookies)
{
postRequest.CookieContainer.Add(cookie);
}
postRequest.Method = "POST";
postRequest.AllowAutoRedirect = true;
using (Stream newStream = postRequest.GetRequestStream())
{
newStream.Write(data, 0, data.Length);
}
using (HttpWebResponse response = (HttpWebResponse)postRequest.GetResponse())
{
this.Cookies = response.Cookies;
}
public CookieCollection Authenticate()
{
this.Connect();
this.ValidateCredentials();
return this.Cookies;
}
The thing is this code relies on synchronous operation (first call Connect(), then ValidateCredentials() ), and it seems WP8 does not support that for Web requests. I could combine the two functions into one, but that won't solve my problem fully since later on this needs to be expanded to access resources behind the UAG, so it would need a modular design.
Is there a way to "force" synchronization?
Thanks
You can still continue your steps in the call back function using the asynchronous model. Or you can use the new HttpClient which can be used with the await keyword so you can program your stuff in a synchronous way.
You can get HttpClient through nuget
install-package Microsoft.Net.Http

As3 - LocalConnection between SWF and AIR desktop app

I need to send a text from an embedded SWF (Web browser) to an AIR based desktop app.
I did everything like explained in the documentation but I can't establish a connection.
Does anybody see what I did wrong or can point me to a working example?
From the SWF:
function startConnection(e:Event=null):void
{
var localConnection:LocalConnection
localConnection = new LocalConnection();
localConnection.client = this;
localConnection.allowDomain("app#com.example.desktop");
var textToSend = "Hello world! Source: http://www.foobar.com";
localConnection.send("app#com.example.desktop:connectionName", "methodName",textToSend);
}
From the AIR desktop app:
function onBrowserInvoke (event:BrowserInvokeEvent):void{
var localConnection:LocalConnection
localConnection = new LocalConnection();
localConnection.client = this
localConnection.allowDomain("example.com");
localConnection.connect("connectionName");
}
Thank you.
Uli
The working code is:
AIR:
var localConnection:LocalConnection = new LocalConnection();
localConnection.send("_myConnection", "methodName", "Hello world! Source: http://www.foobar.com");
SWF:
var localConnection:LocalConnection = new LocalConnection();
localConnection.allowDomain("app#airtest"); //or use "*" wildcard to allow any domains and AIR applications
localConnection.client = this;
localConnection.connect("_myConne‌​ction");
Where airtest is the app id for AIR application. Use the _ symbol before local connection name for supporting unpredictable domain names (it'll work in debug mode and via http).

Getting Error #2032: Stream Error. in Flash while sending url request to server

I am sending http request to server via URLLoader in Flash. My Code is:
var urlLoader:URLLoader=new URLLoader();
var urlRequest:URLRequest=new URLRequest();
var urlparam:URLVariables= new URLVariables();
urlparam.req=JSON.encode(workout);
urlRequest.method="POST";
urlRequest.data=urlparam;
urlRequest.url="http://mydomain.com/saveworkout.php";
urlLoader.addEventListener(Event.COMPLETE,loadCompleted);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,loadError);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
urlLoader.load(urlRequest);
}
private function loadError(event:IOErrorEvent):void{
trace("Stream Error="+event.text);
}
private function securityError(event:SecurityErrorEvent):void{
trace("Security Error="+event.text);
}
private function loadCompleted(event:Event):void{
var urlLoader:URLLoader=event.target as URLLoader;
trace(urlLoader.data);
}
This code works fine when I test it locally and send request to localhost, but giving me Error #2032: Stream Error. At remote server codeigniter framework is being used. I also the crossdomain.xml in the httpdocs directory, and also cross check the request url. Request url opens fine directly in the web browsers. Any idea?
Thanks & Regards,
Check headers in server response.
Maybe it's not of right MIME type or even corrupt.
Browser show it's ok, but in reality its broken. Use Firebug, or Tamperdata plugin for Firefox.

Flex: Export Excel via Servlet

I want a user to press an excel button and get prompted to download an excel file. I normally do it like this:
var dest:String = excelEndpoint;
var request:URLRequest = new URLRequest();
request.url = dest;
fr.download( request,'Locates.xls' );
fr.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleStatus);
fr.addEventListener(IOErrorEvent.IO_ERROR, handleErr);
However, now I need to pass an object to the servlet. Seeing that you can't do that with URLRequest I tried using HTTPService:
var service:HTTPService = new HTTPService();
service.url = excelEndpoint;
service.method = "POST";
service.showBusyCursor = true;
service.addEventListener("result", httpResult);
service.addEventListener("fault", httpFault);
service.send( myObject);
Now I can get my data (myObject) to the servlet successfully, but I don't get prompted for a download.
How can I do that? Is it even possible with HTTPService?
Thanks for any helpful tips.
I don't think there is anything you can do w/ a remote request from the Flash Player to prompt the user to download something. The way I have done this in the past is two fold:
Remote request pings server that generates the excel file and saves it to a temporary directory. The request returns a URL to the Flex app as the result of the call.
When Flex app gets the result--a URL--it creates a URL request and pops it open in a new window, prompting the user to download the generated excel sheet.
I don't see a way to do this in one shot; because the return value from the Flex HTTPService call goes to the Flash Player, not the browser.
SOLVED:
I wanted to accomplish this with 1 remote call and the way I found to do this while passing an object that contained collections is this:
var uv:URLVariables = new URLVariables();
uv.typesColl = myObj.types.toString();
uv.partiesColl = myObj.parties.toString();
uv.statuses = myObj.statuses.toString();
Basically, create a property on the URLVariables object for each collection and then set all collections toString();
Hope that helps someone.