cancel
Showing results for 
Search instead for 
Did you mean: 

How to call authenticated web scripts

sgartner
Champ on-the-rise
Champ on-the-rise
I have enabled the remote object in my Alfresco and so I can call external and internal URLs from my web script like this:


var tabWebScriptUrl = "/authenticatedTabs";

// Initiate a remote connector
var connector = remote.connect("alfresco");

try
  {
    // Get the tabs
    var result = connector.call(tabWebScriptUrl);

    // Process the service return
    if (result !== null)
      {
        model.tabResults = result.toString();
      }
  }
catch (err)
  {
    logger.log("Failure to load tabs from url (" + tabWebScriptUrl + "): " + err.message);
  }

The problem is that it is only calling the web scripts with the "service" authentication methodology instead of "wcservice" that we are using.  I can't seem to figure out how to call these scripts in a way that will allow them to access the user's information.  Here is the error that I'm getting:

The Web Script /alfresco/s/authenticatedTabs has responded with a status of 401 - Unauthorized.

Does anyone know how to get it to work with authenticated scripts (<authentication>user</authentication>)? 

Thanks,
4 REPLIES 4

stevegreenbaum
Champ in-the-making
Champ in-the-making
I believe you need to pass a ticket on your url.  Add "?ticket=ticketinformation" to the end of the url.  You get the ticket information in javascript:  var ticket = session.getTicket()

http://wiki.alfresco.com/wiki/URL_Addressability
http://wiki.alfresco.com/wiki/Security_and_Authentication

sgartner
Champ on-the-rise
Champ on-the-rise
I believe you need to pass a ticket on your url.  Add "?ticket=ticketinformation" to the end of the url.  You get the ticket information in javascript:  var ticket = session.getTicket()
Thanks for the reply, unfortunately this didn't change the behavior at all.

Here is the URL that I'm building:
/authenticatedTabs?guest=false&ticket=TICKET_89ee48cb97ce2b18291e67c4b2a42a0bfdee3575&selectedTab=home

Here is the URL that connect is trying:
http ://localhost:8080/alfresco/s/authenticatedTabs?guest=false&ticket=TICKET_89ee48cb97ce2b18291e67c4b2a42a0bfdee3575&selectedTab=home&guest=true

You can see that I tried adding guest=false to the URL to try to stop it from adding guest=true to the end, but it didn't affect it at all.

stevegreenbaum
Champ in-the-making
Champ in-the-making
One thing to try… alf_ticket=ticketinformation  instead of ticket=…..

I've seen references to one being valid in some circumstances.  For /service, alf_ticket may work. Not sure, but worth a try.  I usually put the ticket parameter at the end of the url….

sgartner
Champ on-the-rise
Champ on-the-rise
One thing to try… alf_ticket=ticketinformation  instead of ticket=…..

This was the, uh, ticket!  Thank you Steve!  I was able to give you two points for both useful messages.

One addition that I discovered however, is that I do have to add guest=false to the url as well as the alf_ticket.  If I just have the alf_ticket on there I get the following error:

Web Script ui_templates/authenticatedTabs.get requires user authentication; however, a guest has attempted access.

FYI