// Register the application with a mastodon instance, // retreive client-credentials and // save them to configuration. public async Task <bool> RegisterApplication(string instance, string appName, string appSite) { using (log.BeginScope($"{ nameof(MastodonInstanceService) }->{ nameof(RegisterApplication) }")) { log.LogDebug("Parameters: {instance}, appName: {appName}, appSite: {appSite}", instance, appName, appSite); try { log.LogDebug("Create mastodon-AppHandler"); using (var appHandler = new AppHandler(instance)) { var appData = await appHandler.CreateAppAsync(appName, scopes, appSite); log.LogDebug("appData returned"); // Save appData cfg.Application.Instance.Name = instance; cfg.Application.Instance.ClientId = appData.client_id; cfg.Application.Instance.ClientSecret = appData.client_secret; cfg.Save(); } } catch (Exception ex) { log.LogError(ex, "RegisterApplication - Exception"); return(false); } } return(true); }
public async Task CreateApp() { using (var appHandler = new AppHandler(Settings.InstanceName)) { var scopes = AppScopeEnum.Read | AppScopeEnum.Write | AppScopeEnum.Follow; var appData = await appHandler.CreateAppAsync("mastodon.NET", scopes, "https://github.com/NicolasConstant/mastodon.NET"); Assert.IsTrue(!string.IsNullOrWhiteSpace(appData.client_secret)); Settings.ClientId = appData.client_id; Settings.ClientSecret = appData.client_secret; } }
public async Task <AppInfoWrapper> GetAppInfoAsync(string mastodonInstanceUrl) { var instances = _instancesRepository.GetAllInstances().ToList(); if (instances.Any(x => x.InstanceUrl == mastodonInstanceUrl)) { return(instances.Find(x => x.InstanceUrl == mastodonInstanceUrl)); } //Create new instance app var appHandler = new AppHandler(mastodonInstanceUrl); var scopes = AppScopeEnum.Read | AppScopeEnum.Write | AppScopeEnum.Follow; var appData = await appHandler.CreateAppAsync("Twittoot", scopes, "https://github.com/NicolasConstant/Twittoot"); //Create new wrapper var appDataWrapper = new AppInfoWrapper(mastodonInstanceUrl, appData); //Save it instances.Add(appDataWrapper); _instancesRepository.SaveInstances(instances.ToArray()); //Returns return(appDataWrapper); }