views:

276

answers:

3

Hi,

I'm developing on a Rails project that uses authlogic for authentication. And I have a part in that project that is realized with Flex, and I need to know how a user can be authenticated if he or she is logged in or not.

I've set up a webservice called UserSessionService and was trying to get the user who is logged in, but it doesn't work. If i try to get it with UserSession.find i just get a # as the result (and therefore thats always true).

Here the UserSessionService.rb require 'weborb/context' require 'rbconfig'

class UserSessionService def login UserSession.find end end

I tried to extend the UserSessionServie class from Authlogic::Session::Base, but that doesn't work too.

Anyone an idea?

thx, tux

A: 

I'm not familiar with Flex, but it seems you're looking for a remote authenticator. Here are some ideas:

  1. Make sure a user can "log in" on the Rails side, and all of that functionality works. You may want to start with http://github.com/binarylogic/authlogic%5Fexample, which is a really good starting place.

  2. Make a "TestController" with one action: #logged_in, which just prints "yes" or "no" based on whether you're logged in or not. Then go hit that in a browser - http://localhost:3000/test/logged%5Fin, and see what it says. Then you can try the same in your Flex app.

    class TestController < ApplicationController
      def logged_in
        render :text => current_user ? 'yes' : 'no'
      end
    end
    
  3. Throw up a debugger in your app where it checks whether they're logged in, and figure out why not. It's usually related to cookies. See http://guides.rubyonrails.org/debugging%5Frails%5Fapplications.html for how to debug in Rails.

Please let me know how it goes!

Colin Curtin
A: 

Hi,

thank you for your answer. The particular problem is, that I'm accessing the rails side with WebORB and so I only have the possibility to access the files in app/services/UserService.rb (for example).

In the Services that are provided by WebORB the functions of the Rails framework aren't accessible. I can't access the current_user function or any other function that is defined in the helpers.

Do you know how I can access that functions or access a controller through WebORB?

thx! tux

23tux
I'm not sure if this will be helpfull as I'm using WebORB for .NET, but in Flex you can setCredentials on a remoteObject. In WebORB.NET you can use an AuthenticationHandler to see who's logged in.
Lieven Cardoen
+1  A: 

I've made it now with an extra HTTPService in Flex that accesses a function in the UserSessions Controller. For more details, look at http://blog.sketchit.de/2009/12/flex-mit-ruby-on-rails-authlogic-authenitifizieren/ (sorry, only in german)

thx for your help! tux

23tux