Jump to content

Repeated Login Best Practice


Recommended Posts

HI all,

It may be because it's still early in the day for me, however I'm having issues trying to figure out best practice for something. My issue is as follows:

I'm automating using an API that requires authentication. Since I need to authorize for every WinHTTP.Open() I've been considering storing the password by setting it using a function like so:

_SetLogin($vData, $sPassword="")
    Local Static $sUser
    Local Static $sPass

    If IsObj($vData) Then ; If oHTTP object
        $vData.SetCredentials($sUser, $sPass, 0)
    Else
        $sUser = $vData
        $sPass = $sPassword
    EndIf
EndFunc

Func _DoThing($sAPI, $iParam1, $iParam2)

    Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")

    $oHTTP.Open("POST", $sAPI & "User/" & $iParam1 & "/Dialogs", False)
    If @error Then Return SetError(1, @extended, @error)

    _SetLogin($oHTTP)

    $oHTTP.Send()
    If @error Then Return SetError(2, 0, 0)

    If $oHTTP.Status <> STATUS_SUCCESS Then Return SetError($oHTTP.Status, 0, $oHTTP.ResponseText)

    Return SetError(0, 0, $oHTTP.ResponseText)

EndFunc

_SetLogin(1234,1234)
_DoThing("http://API/API", 125, 125)

Any advice on if there's better way to do this or any advice on best practice would be appreciated. Thanks in advance!

 

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

  • rcmaehl changed the title to Repeated Login Best Practice

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...