Esempio n. 1
0
        /// <summary>
        /// Initializes the service before MakeApiCall.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="parameters">The method parameters.</param>
        protected override void InitForCall(string methodName, object[] parameters)
        {
            DfaAppConfig config      = this.User.Config as DfaAppConfig;
            string       oAuthHeader = null;

            if (this.GetType().Name == "LoginRemoteService")
            {
                // The choice of OAuth comes only when calling LoginRemoteService.
                // All other services will still use the login token.
                if (config.AuthorizationMethod == DfaAuthorizationMethod.OAuth2)
                {
                    if (this.User.OAuthProvider != null)
                    {
                        oAuthHeader = this.User.OAuthProvider.GetAuthHeader();
                    }
                    else
                    {
                        throw new DfaApiException(null, DfaErrorMessages.OAuthProviderCannotBeNull);
                    }
                }
            }
            else
            {
                if (this.Token == null)
                {
                    this.Token = LoginUtil.GetAuthenticationToken(this.User, this.Signature.Version);
                }
            }

            ContextStore.AddKey("OAuthHeader", oAuthHeader);
            ContextStore.AddKey("RequestHeader", requestHeader);
            ContextStore.AddKey("Token", Token);

            base.InitForCall(methodName, parameters);
        }