Using setCredentials in Flex 2 via Renaun’s RemoteObjectAMF0 in AMFPHP 1.2.5

To skip rant and see solution, scroll to bottom.

This crap was too frikin’ hard to find in Google. After spending 3 hours debugging, I figured out a solution, but not the source of the problem. Following the authentication example at amfphp.org, it just wans’t working. I kept getting an error about the user not having access to the method I was calling, in this case doLogin. Props to Patrick btw for giving us such informative and useful error messages we can catch in our fault handlers.

This, however, didn’t go away when I put in the correct credentials. Credentials are basically the username and password added as a header to the remoting call so the server can authenticate you. This method is on NetConnection, but in ActionScript 2, you’d access it via:

serviceInstance.connection.setCredentials ( "username" , "password" )

and in AS1 via:

serviceInstance.setCredentials ( "username" , "password" )

The AS2 way is the same way it was in Flex 1.5 I think.

Now, the proxying in Abstract service is working. Although the class is dynamic, and I think uses a __resolve like mechnism (returning a make-shift function if that function doesn’t exist on the class instance you are calling ), you can clearly see by ServiceCapture & TamperData that it only makes the 1 remoting call. However, both TamperData and ServiceCapture don’t show the damn headers. I couldn’t figure out how to do traces in AMFPHP to see what the headers were, and I can’t find a NetConnection swf anywhere on my hard drive to use the old NetDebug.trace way.

Now, mx.rpc.AbstractService isn’t included in the Flex source. I put up with this no source bullshit back in Flex 1.5 and was hoping it wouldn’t negatively affect me in Flex 2, but apparently not. GIVE ME THE F’ING CODE, ADOBE! That said, you CAN at least set a breakpoint. Oddly, it was creating a credential variable and I think like using a “:” colon as a seperator; the var was called “cred”. I was wondering if maybe AMFPHP was hardcoded to look for a specific header called “Credentials”, what it was called in Flex 1.5 & Flash 8 on down, and this perhaps changed in Flex 2. Or, maybe the actual names changed to username vs. userid, which was what it was in ActionScript 2. :: shrugs ::

Google didn’t turn up anything (first 10 results anyway), but Renauns blog had a comment with a guy with a similiar problem. He posted his solution. I had problems understanding it, though, because my copies of Cairngorm 2 and 2.1 don’t have the getRPCService, so that through me for a loop, but I saw what he was doing; he was basically manually adding the header. I didn’t want to mess with Renaun’s class, so I did it manually.

It didn’t work. Kept bitching about a null reference. Digging in Renaun’s code, the connection “gateway_conn” is instantiated via lazy loading. In Flex 1.5 & Flash 8 & 7, this was done in the constructor. Renaun’s, however, does it on the first remoting call you make.

if( gateway_conn == null )
	gateway_conn = new RemotingConnection( endpoint );

So, I first did a call to ping which sets the connection, and then added the header to the connection, THEN called doLogin.

my_ro.ping();
my_ro.gateway_conn.addHeader("Credentials", false, {userid: "admin", password: "myPassword"});

She worked.

SON OF A LAKSJDROItuioqasdf… :: whips out MG42 :: :: lights up office, flooding neihborhood with bullets ::

Speaking of hellfire, my site now works in IE7; I’m not finished, but at least you can read the text. I hope IE burns for all eternity. While I do dig their implementation of RSS, if that is their best attempt at making RSS friendly to users… well.. um… we have a loooooooong way to go. Installing it didn’t fix that dang IE script pop-up error I get in Flex Builder 2 either. Weeeeeeeeeee!!!!!!!!

5 Replies to “Using setCredentials in Flex 2 via Renaun’s RemoteObjectAMF0 in AMFPHP 1.2.5”

  1. Your shiny dark red goodness in firefox is gone. Praise IE7 – making the web blander for the rest of us, one site at a time :/

  2. Thanks. Been trying to get this working for ages as well. Unfortunately I can’t get the ping() function going, so I guess I’ll have to modify Renaun’s code.

  3. I too am having setCredentials problems, trying to use Renaun’s component with Fluorine.

    Your workaround gets me a little further, but then I get the error:

    com.renaun.rpc.RemotingConnection was unable to invoke callback RequestPersistentHeader. error=ReferenceError: Error #1069: Property RequestPersistentHeader not found on com.renaun.rpc.RemotingConnection and there is no default value.

    Are there any examples, anywhere, of Flex2 connecting to an authenticated service on Fluorine? The Fluorine documentation is sparse.

  4. I have the same problem as Tim. Apparently, the ILoginCommand was not found at com.TheSilentGroup.Fluorine.Filter.AuthenticationFilter.AuthenticateFlashClient(AMFContext context, AMFBody body)
    at com.TheSilentGroup.Fluorine.Filter.AuthenticationFilter.Invoke(AMFContext context)

    In my web.config i did put

    What am I doing wrong here?

Comments are closed.