cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
p_eisen
Level 2

IUpdateEx3->Authenticate issue

I am trying to use the Authenticate API call in a C++ program. Here is the relevant code:
[CODE]SAFEARRAYBOUND bounds[2];
bounds[0].lLbound = 0;
bounds[0].cElements = 2;
bounds[1].lLbound = 0;
bounds[1].cElements = 2;

SAFEARRAY *psaFields = ::SafeArrayCreate(VT_BSTR, 2, bounds);

_variant_t varEl1 = L"LocationID";
_variant_t varEl2 = L"161560001";
long vecIdx[2];
vecIdx[0] = 0;
vecIdx[1] = 0;
SafeArrayPutElement (psaFields, vecIdx, (void*)(BSTR*)(&varEl1));
vecIdx[1] = 1;
SafeArrayPutElement (psaFields, vecIdx, (void*)(BSTR*)(&varEl2));

varEl1 = L"Password";
varEl2 = L"password";
vecIdx[0] = 1;
vecIdx[1] = 0;
SafeArrayPutElement (psaFields, vecIdx, (void*)(BSTR*)(&varEl1));
vecIdx[1] = 1;
SafeArrayPutElement (psaFields, vecIdx, (void*)(BSTR*)(&varEl2));

VARIANT varSafeArray;
::VariantInit (&varSafeArray);
varSafeArray.parray = psaFields;
varSafeArray.vt = VT_ARRAY;

VARIANT varRes;
::VariantInit (&varRes);
long lRet = 0;

hr = pUp->Authenticate (&varSafeArray, &varRes, &lRet);[/CODE]

The documentation indicates that the lRet value will return a 1 on success, -1 on connection failure, and 0 on auth failure. the varRes value should contain an error string on Authentication failure.

I am getting hr = S_OK and lRes = 0 (Authentication failure), but there is no message in the varRes indicating what the problem was.

We put logging in the ASP page to indicate when it is hit, and determined that it is not. Am I sending an invalid parameter to the Authenticate function? The SAFEARRAY values (at [0, 0] and [1, 0] are the same values I get from GetAuthenticationParameters(). I've also tried initializing the string result parameter to a set BSTR value, and the function pukes big-time.

We are not using the Agent UI -- all of our update calls will occur in code, so we need to authenticate via code.

-- Thanks
0 Kudos
(2) Replies
Sean_Davidson
Level 2

I'm attempting to use the same method, only in C#.

object saParams = retParams;

string temp = "";
object oTemp = temp;

//update.AutoAuthenticate();
int rez = update.Authenticate(ref saParams, ref oTemp);
update.Download(false);

Running this way, rez is set to 0 and oTemp is still null after the call. If i comment that out and use update.AutoAuthenticate() instead, the usual dialog comes up, I enter my valid response, and update.Download() works correctly.

My string array, retParams, is 2 dimentional with one name/value pair.

retParams.SetValue(authParams.GetValue(i, 0).ToString(), i, 0);
retParams.SetValue("valid string", i, 1);

When update.Authenticate is called, it appears to return immediately. At first, I thought maybe it was trying to authenticate to the wrong server, but I wouldn't have gotten this far if I didn't get the enumerated updates for my product from the correct server.

I have verified that my string array, retParams, is [1,2] with the retParams[0,0] = "MyASPParameter" and retParams[0,1] = "valid response".

Can someone please respond to this if I'm doing it completely wrong, or if I got it correct but maybe there's a bug??? 🙂

Thanks,

Sean
0 Kudos
Ritesh
Level 4

Authenticate API needs the url of the authentication server and it does not allow you specify it via the API call. The API gets the url from the GetAuthenticationParameters API. So you must call that API first.


Also, you need to create a safearray of VARIANTs, not BSTRs.
0 Kudos