Exemplo n.º 1
0
        public static async Task <AppAuthenticator> InitializeAsync(AppAuthInfo appAuthInfo, RefreshInterval refreshInterval = null)
        {
            var baseAppAuthUrl = MozuConfig.BaseAppAuthUrl;

            if (appAuthInfo == null || string.IsNullOrEmpty(baseAppAuthUrl))
            {
                throw new Exception("AppAuthInfo or Base App auth Url cannot be null or empty");
            }

            if (String.IsNullOrEmpty(appAuthInfo.ApplicationId) || String.IsNullOrEmpty(appAuthInfo.SharedSecret))
            {
                throw new Exception("ApplicationId or Shared Secret is missing");
            }

            if (_auth != null && _auth.AppAuthInfo.ApplicationId == appAuthInfo.ApplicationId)
            {
                return(_auth);
            }
            try
            {
                await _semaphoreWaiter.WaitAsync();

                // Double check to make sure that someone else didn't already initialize it while we were waiting
                if (_auth == null || (_auth != null && _auth.AppAuthInfo.ApplicationId != appAuthInfo.ApplicationId))
                {
                    try
                    {
                        _log.Info("Initializing App");
                        var uri = new Uri(baseAppAuthUrl);
                        HttpHelper.UrlScheme = uri.Scheme;
                        var tmp = new AppAuthenticator(appAuthInfo, baseAppAuthUrl, refreshInterval);
                        await tmp.AuthenticateAppAsync();

                        lock (_lockObj)
                        {
                            _auth = tmp;
                        }
                    }
                    finally
                    {
                        _semaphoreWaiter.Release();
                    }
                    _log.Info("Initializing App..Done");
                }
            }
            catch (ApiException exc)
            {
                _log.Error(exc.Message, exc);
                lock (_lockObj)
                {
                    _auth = null;
                }
                throw exc;
            }

            return(_auth);
        }
Exemplo n.º 2
0
        public static async Task <AppAuthenticator> InitializeAsync(AppAuthInfo appAuthInfo, RefreshInterval refreshInterval = null)
        {
            var baseAppAuthUrl = MozuConfig.BaseAppAuthUrl;

            if (appAuthInfo == null || string.IsNullOrEmpty(baseAppAuthUrl))
            {
                throw new Exception("AppAuthInfo or Base App auth Url cannot be null or empty");
            }

            if (String.IsNullOrEmpty(appAuthInfo.ApplicationId) || String.IsNullOrEmpty(appAuthInfo.SharedSecret))
            {
                throw new Exception("ApplicationId or Shared Secret is missing");
            }

            if (_auth != null && _auth.AppAuthInfo.ApplicationId == appAuthInfo.ApplicationId)
            {
                return(_auth);
            }
            try
            {
                _log.Info("Initializing App");
                var uri = new Uri(baseAppAuthUrl);
                HttpHelper.UrlScheme = uri.Scheme;
                var tmp = new AppAuthenticator(appAuthInfo, baseAppAuthUrl, refreshInterval);
                await tmp.AuthenticateAppAsync();

                lock (_lockObj)
                {
                    _auth = tmp;
                }
                _log.Info("Initializing App..Done");
            }
            catch (ApiException exc)
            {
                _log.Error(exc.Message, exc);
                lock (_lockObj)
                {
                    _auth = null;
                }
                throw exc;
            }

            return(_auth);
        }
Exemplo n.º 3
0
		public static async Task<AppAuthenticator> InitializeAsync(AppAuthInfo appAuthInfo,  RefreshInterval refreshInterval = null)
		{
            var baseAppAuthUrl = MozuConfig.BaseAppAuthUrl;
			if (appAuthInfo == null || string.IsNullOrEmpty(baseAppAuthUrl))
				throw new Exception("AppAuthInfo or Base App auth Url cannot be null or empty");

			if (String.IsNullOrEmpty(appAuthInfo.ApplicationId) || String.IsNullOrEmpty(appAuthInfo.SharedSecret))
				throw new Exception("ApplicationId or Shared Secret is missing");

		    if (_auth != null && _auth.AppAuthInfo.ApplicationId == appAuthInfo.ApplicationId)
		        return _auth;
		    try
		    {
                await _semaphoreWaiter.WaitAsync();
                // Double check to make sure that someone else didn't already initialize it while we were waiting
                if (_auth == null || (_auth != null && _auth.AppAuthInfo.ApplicationId != appAuthInfo.ApplicationId))
                {
                    try
		            {
		                _log.Info("Initializing App");
		                var uri = new Uri(baseAppAuthUrl);
		                HttpHelper.UrlScheme = uri.Scheme;
		                var tmp = new AppAuthenticator(appAuthInfo, baseAppAuthUrl, refreshInterval);
		                await tmp.AuthenticateAppAsync();
		                lock (_lockObj)
		                {
		                    _auth = tmp;
		                }
		            }
		            finally
		            {
		                _semaphoreWaiter.Release();
                    }
                    _log.Info("Initializing App..Done");
                }
            }
		    catch (ApiException exc)
		    {
		        _log.Error(exc.Message, exc);
		        lock (_lockObj)
		        {
		            _auth = null;
		        }
		        throw exc;
		    }

		    return _auth;
		}
Exemplo n.º 4
0
		public static async Task<AppAuthenticator> InitializeAsync(AppAuthInfo appAuthInfo,  RefreshInterval refreshInterval = null)
		{
            var baseAppAuthUrl = MozuConfig.BaseAppAuthUrl;
			if (appAuthInfo == null || string.IsNullOrEmpty(baseAppAuthUrl))
				throw new Exception("AppAuthInfo or Base App auth Url cannot be null or empty");

			if (String.IsNullOrEmpty(appAuthInfo.ApplicationId) || String.IsNullOrEmpty(appAuthInfo.SharedSecret))
				throw new Exception("ApplicationId or Shared Secret is missing");

		    if (_auth != null && _auth.AppAuthInfo.ApplicationId == appAuthInfo.ApplicationId)
		        return _auth;
		    try
		    {
		        _log.Info("Initializing App");
		        var uri = new Uri(baseAppAuthUrl);
		        HttpHelper.UrlScheme = uri.Scheme;
		        var tmp = new AppAuthenticator(appAuthInfo, baseAppAuthUrl, refreshInterval);
		        await tmp.AuthenticateAppAsync();
		        lock (_lockObj)
		        {
		            _auth = tmp;
		        }
		        _log.Info("Initializing App..Done");

		    }
		    catch (ApiException exc)
		    {
		        _log.Error(exc.Message, exc);
		        lock (_lockObj)
		        {
		            _auth = null;
		        }
		        throw exc;
		    }

		    return _auth;
		}