Expand my Community achievements bar.

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.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----