コード例 #1
0
        public override async Task RefreshAuthenticationAsync()
        {
            try
            {
                var smintIoSettingsDatabaseModel = await _smintIoSettingsDatabaseProvider.GetSmintIoSettingsDatabaseModelAsync().ConfigureAwait(false);

                smintIoSettingsDatabaseModel.ValidateForAuthenticator();

                TokenEndPointUri = new Uri($"https://{smintIoSettingsDatabaseModel.TenantId}.smint.io/connect/token");
                ClientId         = smintIoSettingsDatabaseModel.ClientId;
                ClientSecret     = smintIoSettingsDatabaseModel.ClientSecret;

                await base.RefreshAuthenticationAsync();
            }
            catch (AuthenticatorException e)
            {
                throw new SmintIoAuthenticatorException(e.Error, e.Message);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error refreshing Smint.io OAuth access token");

                throw new SmintIoAuthenticatorException(AuthenticatorException.AuthenticatorError.CannotRefreshToken,
                                                        $"Refreshing the Smint.io OAuth access token failed: {ex.Message}");
            }
        }
コード例 #2
0
        public override async Task InitializeAuthenticationAsync()
        {
            try
            {
                var smintIoSettingsDatabaseModel = await _smintIoSettingsDatabaseProvider.GetSmintIoSettingsDatabaseModelAsync().ConfigureAwait(false);

                if (string.IsNullOrEmpty(smintIoSettingsDatabaseModel.RefreshToken))
                {
                    throw new Exception("No refresh token present in settings");
                }

                smintIoSettingsDatabaseModel.ValidateForAuthenticator();

                TokenEndPointUri = new Uri($"https://{smintIoSettingsDatabaseModel.TenantId}.smint.io/connect/token");
                ClientId         = smintIoSettingsDatabaseModel.ClientId;
                ClientSecret     = smintIoSettingsDatabaseModel.ClientSecret;
                RefreshToken     = smintIoSettingsDatabaseModel.RefreshToken;

                await base.RefreshAuthenticationAsync().ConfigureAwait(false);
            }
            catch (AuthenticatorException e)
            {
                throw new SmintIoAuthenticatorException(e.Error, e.Message);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error acquiring Smint.io OAuth access token through refresh token");

                throw new SmintIoAuthenticatorException(AuthenticatorException.AuthenticatorError.CannotAcquireToken,
                                                        $"Acquiring the Smint.io OAuth access token through refresh token failed: {ex.Message}");
            }
        }
コード例 #3
0
        private async Task StartPusherAsync()
        {
            var smintIoSettingsDatabaseModel = await _smintIoSettingsDatabaseProvider.GetSmintIoSettingsDatabaseModelAsync();

            smintIoSettingsDatabaseModel.ValidateForPusher();

            var pusherAuthEndpoint = $"https://{smintIoSettingsDatabaseModel.TenantId}.clapi.smint.io/consumer/v1/notifications/pusher/auth";

            var tokenDatabaseModel = await _smintIoTokenDatabaseProvider.GetTokenDatabaseModelAsync();

            tokenDatabaseModel.ValidateForPusher();

            var authorizer = new HttpAuthorizer(pusherAuthEndpoint, tokenDatabaseModel.AccessToken);

            _pusher = new Pusher("32f31c26a83e09dc401b", new PusherOptions()
            {
                Cluster    = "eu",
                Authorizer = authorizer
            });

            _pusher.ConnectionStateChanged += ConnectionStateChanged;
            _pusher.Error += PusherError;

            var connectionState = await _pusher.ConnectAsync();

            if (connectionState == ConnectionState.Connected)
            {
                await SubscribeToPusherChannelAsync((int)smintIoSettingsDatabaseModel.ChannelId);
            }
        }
コード例 #4
0
        public override async Task InitializeAuthenticationAsync()
        {
            try
            {
                var smintIoSettingsDatabaseModel = await _smintIoSettingsDatabaseProvider.GetSmintIoSettingsDatabaseModelAsync().ConfigureAwait(false);

                smintIoSettingsDatabaseModel.ValidateForAuthenticator();

                AuthorityEndpoint    = new Uri($"https://{smintIoSettingsDatabaseModel.TenantId}.smint.io/.well-known/openid-configuration");
                ClientId             = smintIoSettingsDatabaseModel.ClientId;
                ClientSecret         = smintIoSettingsDatabaseModel.ClientSecret;
                Scope                = "smintio.full openid profile offline_access";
                TargetRedirectionUrl = new Uri(smintIoSettingsDatabaseModel.RedirectUri);

                await base.InitializeAuthenticationAsync();
            }
            catch (AuthenticatorException e)
            {
                throw new SmintIoAuthenticatorException(e.Error, e.Message);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error acquiring Smint.io OAuth access token through system browser");

                throw new SmintIoAuthenticatorException(AuthenticatorException.AuthenticatorError.CannotAcquireToken,
                                                        $"Acquiring the Smint.io OAuth access token through system browser failed: {ex.Message}");
            }
        }
コード例 #5
0
        public async Task <SmintIoGenericMetadata> GetGenericMetadataAsync()
        {
            _logger.LogInformation("Receiving generic metadata from Smint.io...");

            await SetupClapicOpenApiClientAsync();

            var syncGenericMetadata = await _retryPolicy.ExecuteAsync(async() =>
            {
                // get a new access token in case it was refreshed
                var tokenDatabaseModel           = await _smintIoTokenDatabaseProvider.GetTokenDatabaseModelAsync();
                _clapicOpenApiClient.AccessToken = tokenDatabaseModel.AccessToken;
                return(await _clapicOpenApiClient.GetGenericMetadataForSyncAsync());
            }
                                                                      );

            var smintIoGenericMetadata = new SmintIoGenericMetadata();

            var smintIoSettingsDatabaseModel = await _smintIoSettingsDatabaseProvider.GetSmintIoSettingsDatabaseModelAsync();

            var importLanguages = smintIoSettingsDatabaseModel.ImportLanguages;

            smintIoGenericMetadata.ContentProviders = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.Providers);

            smintIoGenericMetadata.ContentTypes = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.Content_types);
            smintIoGenericMetadata.BinaryTypes  = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.Binary_types);

            smintIoGenericMetadata.ContentCategories = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.Content_categories);

            smintIoGenericMetadata.LicenseTypes  = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_types);
            smintIoGenericMetadata.ReleaseStates = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.Release_states);

            smintIoGenericMetadata.LicenseExclusivities = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_exclusivities);
            smintIoGenericMetadata.LicenseUsages        = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_usages);
            smintIoGenericMetadata.LicenseSizes         = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_sizes);
            smintIoGenericMetadata.LicensePlacements    = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_placements);
            smintIoGenericMetadata.LicenseDistributions = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_distributions);
            smintIoGenericMetadata.LicenseGeographies   = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_geographies);
            smintIoGenericMetadata.LicenseIndustries    = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_industries);
            smintIoGenericMetadata.LicenseLanguages     = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_languages);
            smintIoGenericMetadata.LicenseUsageLimits   = GetGroupedMetadataElementsForImportLanguages(importLanguages, syncGenericMetadata.License_usage_limits);

            _logger.LogInformation("Received generic metadata from Smint.io");

            return(smintIoGenericMetadata);
        }
コード例 #6
0
        public async Task SynchronizeAsync(bool synchronizeGenericMetadata)
        {
            try
            {
                var smintIoSettingsDatabaseModel = await _smintIoSettingsDatabaseProvider.GetSmintIoSettingsDatabaseModelAsync();

                smintIoSettingsDatabaseModel.ValidateForSync();

                if (!_syncTarget.GetCapabilities().IsMultiLanguageSupported() &&
                    smintIoSettingsDatabaseModel.ImportLanguages.Length > 1)
                {
                    throw new SyncJobException(
                              SyncJobException.SyncJobError.Generic,
                              "SyncTarget supports only one language but multiple language are set to be synced!"
                              );
                }

                var smintIoTokenDatabaseModel = await _smintIoTokenDatabaseProvider.GetTokenDatabaseModelAsync();

                smintIoTokenDatabaseModel.ValidateForSync();

                await _syncTargetAuthenticator.InitializeAuthenticationAsync();

                var cancelTask = !await _syncTarget.BeforeSyncAsync();

                if (cancelTask)
                {
                    _logger.LogInformation("BeforeSync task terminated with 'false', indicating to abort sync");

                    return;
                }

                if (!_syncTarget.GetCapabilities().IsCustomizedMetadataSynchronization())
                {
                    if (synchronizeGenericMetadata ||
                        _contentProviderCache == null)
                    {
                        await SynchronizeGenericMetadataAsync();
                    }
                }

                await SynchronizeAssetsAsync();

                await _syncTarget.AfterSyncAsync();
            }
            catch (AuthenticatorException e)
            {
                _logger.LogError(e, "Error in sync job");

                await _syncTarget.HandleAuthenticatorExceptionAsync(e);
            }
            catch (SyncJobException e)
            {
                _logger.LogError(e, "Error in sync job");

                await _syncTarget.HandleSyncJobExceptionAsync(e);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error in sync job");

                await _syncTarget.HandleSyncJobExceptionAsync(new SyncJobException(SyncJobException.SyncJobError.Generic, e.Message));
            }
        }