Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass System.Net.ICredentials to API?

Tags:

c#

First, credentials are given for authentication with said API:

Webservice.Authenticate.Credential credential = new Webservice.Authenticate.Credential
{
    Username = "myUserName",
    Password = GetMD5("myPassword"), // See below for a MD5 encoding example method
    ApplicationId = new Guid("00000000-0000-0000-0000-000000000000"), //YOUR ID HERE
    IdentityId = new Guid("00000000-0000-0000-0000-000000000000") //Default is empty guid (no need to edit this)
};

If I try to directly utilize the credentials as Icredentials, like so _service.Credentials = credential; the following error occurs:

Cannot implicitly convert type auth.credential to system.net.icredentials. I attempted to cast it, but it did not work correctly.

Later, I tried to utilize the credentials in this manner when another service is called. However, I am unsure of how to pass the credentials.

TransactionService.TransactionService _service = new TransactionService.TransactionService();
TransactionService.TransactionSearchParameters _params = new TransactionService.TransactionSearchParameters();
_service.Credentials = new NetworkCredential(credential.Username, credential.Password);
like image 912
J.J. Avatar asked Feb 10 '23 21:02

J.J.


1 Answers

System.Net.ICredentials is a collection.

Try:

_service.Credentials.Add("uri:my.uri"
   , "authenticationType"
   , new NetworkCredential(credential.Username, credential.Password)
);
like image 100
Steffen Mangold Avatar answered Feb 12 '23 10:02

Steffen Mangold