Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

Custom Authentication Failing Ajax

Avatar

Former Community Member

Hi,

I have written a custom Authentication based on Sling form based Authentication. I followed http://www.wemblog.com/2013/03/how-to-create-custom-authentication.html article  to do that. I am trying to invoke the handler with Ajax call and it seems like the call is never going into the handler.

But if i invoke it with CURL it invokes fine and gives me response i expect. Below CURL is being used. My Handler expects Json input of username and password.

curl -i -X POST -d '{"username":"admin","password":"admin","keepLoggedIn":true}' -H 'Content-Type: application/json' localhost:4503/j_mycustom_security_check

The Ajax call that i am doing is :

var username = "admin"; var password = "admin"; var apiURL = "http://localhost:4503/content/j_mycustom_security_check" var jsonPayload = { username: username, password: password }; $.ajax({ url: apiURL, type: "POST", data: JSON.stringify(jsonPayload), contentType: "application/json", success : function(data, status, xhr) { console.log("sucess"+status); }, error: function (xhr, ajaxOptions, thrownError) { console.log('error'+thrownError); } });

I can see the handler in handlers tab and i have added the j_mycustom_security_check in Sling Authenticator service in OSGI. Can anybody point out how can i resolve this? Thanks in advance.

When i keep the apiURL param as 

http://localhost:4503/content/j_mycustom_security_check
i get 403 Forbidden response, while if i use 
http://localhost:4503/content/j_mycustom_security_check.html i get success 200 always. However, in both cases my Authentication code is not getting invoked. But in case of curl it does.
1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi,

I solved this my changing the preference of my custom authentication handler service ranking parameter. Token Authentication handle was rejecting the request and therefore the request wasn't entering my handler. However, once that was changed i got a 500 error. After that i had to change the path for the handler. Earlier this handler was accepting all the path i.e. root path (/), i changed it to my application specific path and all was good.

View solution in original post

1 Reply

Avatar

Correct answer by
Former Community Member

Hi,

I solved this my changing the preference of my custom authentication handler service ranking parameter. Token Authentication handle was rejecting the request and therefore the request wasn't entering my handler. However, once that was changed i got a 500 error. After that i had to change the path for the handler. Earlier this handler was accepting all the path i.e. root path (/), i changed it to my application specific path and all was good.