GithubHelp home page GithubHelp logo

Windows authentication about vba-web HOT 5 CLOSED

vba-tools avatar vba-tools commented on August 28, 2024
Windows authentication

from vba-web.

Comments (5)

opoani avatar opoani commented on August 28, 2024 3

If you want windows authentication and SSO then you might try this hack by changing :

Public Function PrepareHttpRequest(Request As RestRequest, TimeoutMS As Long, _
    Optional UseAsync As Boolean = False) As Object
    Dim http As Object
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    'This is the options: 
'typedef enum WinHttpRequestAutoLogonPolicy { 
 ' AutoLogonPolicy_Always             = 0,
 ' AutoLogonPolicy_OnlyIfBypassProxy  = 1,
'  AutoLogonPolicy_Never              = 2
' } WinHttpRequestAutoLogonPolicy;

    http.SetAutoLogonPolicy 0

    ' Set timeouts
    http.setTimeouts TimeoutMS, TimeoutMS, TimeoutMS, TimeoutMS

    ' Pass http to request and setup onreadystatechange
    If UseAsync Then
        Set Request.HttpRequest = http
        http.onreadystatechange = Request
    End If

    Set PrepareHttpRequest = http
End Function

Potential unexpected side effects, well might be so haven't tested all cases.
It worked for me to do post / get towards an internal WCF with windows security. That said the conclusion is that your mileage might vary...

(Added code formatting)

from vba-web.

timhall avatar timhall commented on August 28, 2024

Hi @sravikiran, I'm not too familiar with Windows authentication, but I think the following should help. First, I would recommend checking out the wiki for details on implementing your own IAuthenticator. Using that approach, I would skip the Setup step, use the standard HttpOpen, and define the following BeforeExecute:

Private Function GenerateToken(Username As String) As String
    ' Your specific details for generating a token
    GenerateToken = Username
End Function

Private Sub IAuthenticator_BeforeExecute(Request As RestRequest)
    Request.AddHeader "Authorization", GenerateToken(Application.UserName)
End Sub

Reading more about "Windows integrated authentication" (NTLM) (this Stack Overflow question has a good breakdown) it seems much more complicated than simply creating a token based on the user id, is that what you are trying to implement? If so, I can look into creating a Windows Integrated Authenticator.

from vba-web.

sravikiran avatar sravikiran commented on August 28, 2024

Hi @timhall ,

Sorry for the slow response. Thanks for the insights. I wasn't aware that the windows authenticator sends messages with the request to the server to get the user authenticated. When I hit the get endpoints of the REST API using a browser, the browser sets the Authorization header value, I thought it is the authorization token.

It will be great if you can create an authenticator for Windows Integrated Authentication, as it will be useful for anyone looking for what I asked here. Thanks.

from vba-web.

kimptoc avatar kimptoc commented on August 28, 2024

Hi,

Not sure what kind of Windows authentication you need, but I have an internal site that uses Windows Auth.

If you need a manual/specific set of credentials used, then these can be passed on the open call, as seen here:
http://zanstra.home.xs4all.nl/inTec/ServerXMLHTTP.htm

Thus a custom Windows version of IAuthenticator could be created.

What I need is to use the current users credentials, which happens auto-magically if you use XMLHTTP instead of ServerXMLHTTP. So I switched the PrepareHttpRequest function to create one of those instead and that worked without specifying credentials anywhere.

It does not seem to have a setTimeouts method (at least not with the same name).

Any reason why ServerXMLHTTP is used, as opposed to the XMLHTTP class?

from vba-web.

timhall avatar timhall commented on August 28, 2024

@opoani Cool! I was just about to write this off, I'll see if I can integrate that in v4.0.0

from vba-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.