hkn-a
hkn-a

Reputation: 23

DocuSign foldersapi authentication problem in C# wrong username or password

I have downloaded the console application from DocuSign website (JWT grant remote signing). It is working well but when I try to use FoldersApi it is throwing a "USER_AUTHENTICATION_FAILED One or both of Username and Password are invalid. Invalid access token" error. Is it somehow related to apiClient? How was it able to send email if the username and password is wrong?

namespace DocuSign.CodeExamples.JWT_Console
{
    class Program
    {
        static readonly string DevCenterPage = "https://developers.docusign.com/platform/auth/consent";

        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.White;
            OAuthToken accessToken = null;
            try
            {
                accessToken = JWTAuth.AuthenticateWithJWT("ESignature", ConfigurationManager.AppSettings["ClientId"], ConfigurationManager.AppSettings["ImpersonatedUserId"],
                                                            ConfigurationManager.AppSettings["AuthServer"], ConfigurationManager.AppSettings["PrivateKeyFile"]);
            }
            catch (ApiException apiExp)
            {
              //Removed this section because it is not helpful to the question
            }

            var apiClient = new ApiClient();
            apiClient.SetOAuthBasePath(ConfigurationManager.AppSettings["AuthServer"]);
            UserInfo userInfo = apiClient.GetUserInfo(accessToken.access_token);
            Account acct = userInfo.Accounts.FirstOrDefault();
            FoldersApi foldersApi = new FoldersApi(apiClient);
            foreach (var folder in foldersApi.List(acct.AccountId).Folders)
            {
                Console.WriteLine(folder.Name);
            }
            
        }
    }
}

debugging screen

Upvotes: 0

Views: 74

Answers (1)

hkn-a
hkn-a

Reputation: 23

It turns out the problem was BaseUri. Posting the working code below.

    var apiClient = new ApiClient();
    apiClient.SetOAuthBasePath(ConfigurationManager.AppSettings["AuthServer"]);
    UserInfo userInfo = apiClient.GetUserInfo(accessToken.access_token);
    Account acct = userInfo.Accounts.FirstOrDefault();
    apiClient.SetBasePath((acct.BaseUri + "/restapi"));
    FoldersApi foldersApi = new FoldersApi(apiClient);
    
    foreach (var folder in foldersApi.List(acct.AccountId).Folders)
    {
        Console.WriteLine(folder.Name);
    }

Upvotes: 1

Related Questions