Avatar of Richard M.
Richard M.
 asked on

Integrated Windows authentication using AJAX in an html page.

I am trying to write a Javascript using AJAX to get and send the windows credentials to the server app for integrated windows authentication and have a web page returned that represents the roles of the user.  I am using red hat developer studio and wildfly 15.  I am tackling this one thing at a time.  The first step is to send the credentials.  This is what I have so far.  I am pretty new at developing, so I would appreciate any feedback.  I know I am missing the script tag to start it.  There are other things that are not relevant, so I did not include them.

var service_url = "http://192.168.20.200:8080"
$.ajax({
    type: "GET",
    url: service_url,
    dataType: "xml",
    data: "ParamId=" + FormId.value,
    processData: false,
    beforeSend : function(req) {
         req.setRequestHeader('Authorization',
               make_base_auth ('USERNAME', 'PASSWORD'));
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {  
         ajaxError(XMLHttpRequest, textStatus, errorThrown);
    },
    success: function(success); }
    function success()
    {<alert SUCCESS!> }
});
</script>
Web DevelopmentJavaScriptWindows OSAJAX

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

Hi Richard,

Looks like this is your first question - welcome to EE.


Just trying to understand what it is you are looking for?

Does your code not work?

Can you give us some more information about what you are expecting and what you are observing.
Richard M.

ASKER
To tell you the truth, I have not been able to ascertain whether or not the code is working.  The beginning part of the script sets up some text and a button and tells the user to press the button to authenticate.  When I press the button, the success function does not seem to be working.  After some thought I realize I have not built the server app to handle the request yet, but I also am not getting an error message.  Is there a way to test whether or not my script is working?
Julian Hansen

Your script is setup to make an AJAX call to a server resource so there are two sides to this equation - a working solution is when both sides are doing what they are supposed to do.

Before looking at the AJAX side it is important to determine if your server code is working.

Your URL points to http://192.168.20.200:8080
That suggests that there is some code on the end of that link that is going to return some XML.

From your second post it sounds like you have jumped in the deep end so let's go back to the beginning.

Is this code you have written or did you copy it from somewhere?
What are you expecting it to do?
Would it be helpful to go through it line by line to break it down or are you ok with what it is doing?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Richard M.

ASKER
I think I have an understanding of what it is supposed to be doing.  I copied a bulk of the code, then changed it (hopefully correctly) for my environment.

I am expecting the code to get the windows credentials from the logged on user and then request the xml files with the auth information.

If that is not correct, I am happy to accept critiques, etc.
Julian Hansen

The JavaScript code has nothing to do with windows. All it is doing is calling a URL and then responding to the content returned from that URL.

The key is what is at the other end of that URL.

On return the code does nothing - so unless the purpose is to change state on the server AND there is a script listening on http://192.168.20.200:8080 the script does not do anything.
Richard M.

ASKER
So you are saying that it does not collect the IWA credentials?  I think I am just going to start from scratch.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Richard M.

ASKER
Thank you so much.  I will try this.  I am marking it as the answer.  I really appreciate your help.
Julian Hansen

You are welcome.
Richard M.

ASKER
Thank you very much for your help.  I believe I have it now and am working on the server side for authenticating the user to the application.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Julian Hansen

again you are most welcome.