We help IT Professionals succeed at work.

Integrated Windows authentication using AJAX in an html page.

124 Views
Last Modified: 2019-02-06
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>
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
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.Software Developer II

Author

Commented:
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?
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
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?
Richard M.Software Developer II

Author

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
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.Software Developer II

Author

Commented:
So you are saying that it does not collect the IWA credentials?  I think I am just going to start from scratch.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Richard M.Software Developer II

Author

Commented:
Thank you so much.  I will try this.  I am marking it as the answer.  I really appreciate your help.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
You are welcome.
Richard M.Software Developer II

Author

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
again you are most welcome.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.