Pode icon indicating copy to clipboard operation
Pode copied to clipboard

Route with authentication via IIS

Open ThomasPerezBlanco opened this issue 2 years ago • 7 comments

Hello,

I'm trying to have a route with authentication via IIS. When I run through an internet browser, I have no problem. However, when I run PowerShell I get the following error:

image

I don't know how to put the header for IIS. The end goal is to execute a request via AJAX.

Can you help me please ?

Thank you.

Cordially,

Thomas.

ThomasPerezBlanco avatar May 23 '22 10:05 ThomasPerezBlanco

Hi Thomas,

you'll need to add the -UseDefaultCredentials to Invoke-RestMethod / Invoke-WebRequest in order to use Windows Integrated Authentication from those Cmdlets.

RobinBeismann avatar May 23 '22 10:05 RobinBeismann

I know I can do it that way, but the goal is to run the request on AJAX or other method than PowerShell. From what I understand, everything happens in the header... but I don't know how to build it.

Thx.

ThomasPerezBlanco avatar May 23 '22 10:05 ThomasPerezBlanco

Basically you just need to tell the client that is requesting (in this case PowerShell) to use integrated authentication.

For Ajax you can do it this way for example:

    $.ajax({
        type: 'POST', 
        url: url, 
        xhrFields: {
            withCredentials: true
        },
        dataType: 'json',
        contentType: 'application/json',
        data: JSON.stringify(requestdata),
        success: function (data) { 
            console.log(data.ObjectID);
        }
    });

RobinBeismann avatar May 23 '22 10:05 RobinBeismann

I will try, thanks for your help.

ThomasPerezBlanco avatar May 23 '22 12:05 ThomasPerezBlanco

Did it work?

RobinBeismann avatar May 24 '22 22:05 RobinBeismann

Hello,

Now I have an error:

image

Do you know how I can correct it?

thank you.

Cordially,

Thomas PEREZ.

ThomasPerezBlanco avatar May 25 '22 08:05 ThomasPerezBlanco

Yes, you need to set the Access-Control-Allow-Origin Header according to the URL you're accessing from. Are you hosting your JS Files at Pode or on another Webserver?

RobinBeismann avatar May 26 '22 14:05 RobinBeismann

Closing this issue, if it's still a problem feel free to re-open.

Badgerati avatar Oct 07 '23 17:10 Badgerati