/// <summary> /// This contructor does application authentication and setups up the necessary timers to keep the app auth ticket valid. /// </summary> /// <param name="appId">The application version's app id</param> /// <param name="sharedSecret">The application version's shared secret</param> /// <param name="baseAppAuthUrl">The base URL of the Mozu application authentication service</param> private AppAuthenticator(AppAuthInfo appAuthInfo, string baseAppAuthUrl, RefreshInterval refreshInterval = null) { BaseUrl = baseAppAuthUrl; _appAuthInfo = appAuthInfo; _refreshInterval = refreshInterval; MozuConfig.SharedSecret = appAuthInfo.SharedSecret; MozuConfig.ApplicationId = appAuthInfo.ApplicationId; }
private void SetRefreshIntervals(bool updateRefreshTokenInterval) { if (_refreshInterval == null) { _log.Info(String.Format("Access token expires at : {0}", AppAuthTicket.AccessTokenExpiration)); _log.Info(String.Format("Refresh token expires at : {0}", AppAuthTicket.RefreshTokenExpiration)); _refreshInterval = new RefreshInterval((long)(AppAuthTicket.AccessTokenExpiration - DateTime.Now).TotalSeconds - 180, (long)(AppAuthTicket.RefreshTokenExpiration - DateTime.Now).TotalSeconds - 180); } _refreshInterval.UpdateExpirationDates(updateRefreshTokenInterval); }
public static AppAuthenticator Initialize(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 != null && _auth.AppAuthInfo.ApplicationId != appAuthInfo.ApplicationId)) { _semaphoreWaiter.Wait(); lock (_lockObj) { try { _log.Info("Initializing App"); var uri = new Uri(baseAppAuthUrl); HttpHelper.UrlScheme = uri.Scheme; _auth = new AppAuthenticator(appAuthInfo, baseAppAuthUrl, refreshInterval); _auth.AuthenticateApp(); _log.Info("Initializing App..Done"); } catch (ApiException exc) { _log.Error(exc.Message, exc); _auth = null; throw exc; } finally { _semaphoreWaiter.Release(); } } } return(_auth); }
public static AppAuthenticator Initialize(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 != null && _auth.AppAuthInfo.ApplicationId != appAuthInfo.ApplicationId)) { _semaphoreWaiter.Wait(); lock (_lockObj) { try { _log.Info("Initializing App"); var uri = new Uri(baseAppAuthUrl); HttpHelper.UrlScheme = uri.Scheme; _auth = new AppAuthenticator(appAuthInfo, baseAppAuthUrl, refreshInterval); _auth.AuthenticateApp(); _log.Info("Initializing App..Done"); } catch (ApiException exc) { _log.Error(exc.Message, exc); _auth = null; throw exc; } finally { _semaphoreWaiter.Release(); } } } return _auth; }
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; }
private void SetRefreshIntervals(bool updateRefreshTokenInterval) { if (_refreshInterval == null) { _log.Info(String.Format("Access token expires at : {0}", AppAuthTicket.AccessTokenExpiration )); _log.Info(String.Format("Refresh token expires at : {0}", AppAuthTicket.RefreshTokenExpiration )); _refreshInterval = new RefreshInterval((long) (AppAuthTicket.AccessTokenExpiration - DateTime.Now).TotalSeconds - 180, (long)(AppAuthTicket.RefreshTokenExpiration - DateTime.Now).TotalSeconds - 180); } _refreshInterval.UpdateExpirationDates(updateRefreshTokenInterval); }
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); }
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; }
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); }