Ejemplo n.º 1
0
        internal static AuthenticationResult Authenticate(String username, String password, String consumerKey, String consumerSecret, String evernoteHost, UserStore.Client userStore)
        {
            AuthenticationResult authResult;
            try
            {
                authResult = userStore.authenticate(username, password, consumerKey, consumerSecret);
            }
            catch (EDAMUserException ex)
            {
                String parameter = ex.Parameter;
                EDAMErrorCode errorCode = ex.ErrorCode;

                if (parameter.ToLower() == "consumerkey")
                {
                    throw new ApplicationException("API Key Missing. \r\n Please download latest en2ki release from homepage");
                }
                else
                {
                    throw new ApplicationException(String.Format("Authentication Failed \r\n (Make sure {0} is correct)", parameter));
                }
            }
            return authResult;
        }
        /// <summary>
        /// 認証
        /// </summary>
        /// <param name="userStore"></param>
        /// <returns></returns>
        private string GetAuthToken(UserStore.Client userStore)
        {
            try
            {
                AuthenticationResult authResult = null;
                authResult = userStore.authenticate(mUserName, mPassword, mConsumerKey, mConsumerSecret, false);
                //authResult = userStore.authenticate(mUserName, mPassword, mConsumerKey, mConsumerSecret, true);
                return authResult.AuthenticationToken;
            }
            catch (EDAMUserException ex)
            {
                EDAMErrorCode errorCode = ex.ErrorCode;
                String param = ex.Parameter;

                Console.WriteLine("エラーコード:" + errorCode);
                Console.WriteLine("パラメータ:" + param);
                Console.WriteLine("mConsumerKey: " + mConsumerKey);
                Console.WriteLine("mEvernoteHost: " + mEvernoteHost);
                throw new ApplicationException("認証に失敗しました。", ex);
            }
        }