Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IIS Windows Auth Intermittent 401.1 #2121

Closed
arj01a opened this issue Jul 17, 2024 · 10 comments
Closed

IIS Windows Auth Intermittent 401.1 #2121

arj01a opened this issue Jul 17, 2024 · 10 comments

Comments

@arj01a
Copy link

arj01a commented Jul 17, 2024

Expected Behavior / New Feature

Ocelot should be working with Windows Authentication

Actual Behavior / Motivation for New Feature

Ocelot should be working with Windows Authentication

Steps to Reproduce the Problem

I have deployed the Gateway on IIS with anonymous.
The service is deployed on IIS with windows authentication.

I managed to get this working with one issue that all requests were being made under the first user. To solve this I enabled authPersistSingleRequest=True

This caused a subsequent issue whereby when making multiple requests (approx. 6 or more) in quick succession some of the requests receive a 401.1 error "The token supplied to the function is invalid".

I have tested setting authPersistSingleRequest=True without using the Gateway and this works without the above issue.

Please can you assist me with this issue?

Specifications

  • Version: 23.3
  • Platform: Windows 2016 IIS 10
  • Subsystem:
@raman-m
Copy link
Member

raman-m commented Jul 17, 2024

Dear @arj01a,
Who are you? Why is your account anonymous?

@arj01a
Copy link
Author

arj01a commented Jul 17, 2024

Hello,
I am software engineer trying to use Ocelot as a Gateway.
This is my first post on GitHub.
I would appreciate any assistance.
Thanks

@raman-m
Copy link
Member

raman-m commented Jul 17, 2024

I mean, what's your full name? What's your LinkedIn?
We don't accept issues from anonymous GitHub users.

@raman-m
Copy link
Member

raman-m commented Jul 17, 2024

Duplicate of #657

@raman-m raman-m marked this as a duplicate of #657 Jul 17, 2024
@raman-m
Copy link
Member

raman-m commented Jul 17, 2024

I managed to get this working with one issue that all requests were being made under the first user. To solve this I enabled authPersistSingleRequest=True

For a detailed explanation, refer to the comment in this issue: #657 (comment).
The pull request #1521 should address the problem with any Windows Authentication issues.

I have tested setting authPersistSingleRequest=True without using the Gateway and this works without the above issue.
Please can you assist me with this issue?

Consider the following workaround until merge #1521 is complete: you'll need to define two routes for Windows authentication:

  • The first is an anonymous route without authentication options. You may need to implement a coding hack to include UseDefaultCredentials in the delegating handler.
  • The second is for after you've received the Windows authentication artifacts (tokens, cookies), at which point you call another authenticated route.

This method should be applicable for any authentication providers and custom authentications not integrated into Ocelot.
I hope this is helpful!

@raman-m
Copy link
Member

raman-m commented Jul 17, 2024

Will be fixed by #1521

@raman-m raman-m closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2024
@arj01a
Copy link
Author

arj01a commented Jul 17, 2024

Thanks for the information, I will give the workaround a try with setting UseDefaultCredentials in the delegating handler

@raman-m
Copy link
Member

raman-m commented Jul 17, 2024

Good luck!

@arj01a
Copy link
Author

arj01a commented Jul 19, 2024

Just a quick update.
I have managed to get the gateway working with Windows Authenication on IIS, here are the steps if it helps someone in the future

IIS Gateway => Windows Authentication
IIS Service => Windows Authentication

authPersistSingleRequest=False

  1. Implemented a Delegating Handler to set UseDefaultCredentials
  2. Set the Http Handler Option "PooledConnectionLifeTime" to 0 (so not to reuse an existing connection).
  3. Set the value BackConnectionHostNames in the registry => key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0 to my site. (this step is only relevant if you host the gateway and the service on the same computer).

All steps had to be completed for the gateway to work with my set-up.

Thanks for your help and guidance.

@raman-m
Copy link
Member

raman-m commented Jul 19, 2024

Congratulations, anonymous user! Your journey with IIS has concluded. However, this solution is not applicable for self-hosted scenarios such as Kestrel in Docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants