public async Task LoadAppAsync() { Mastonet.Entities.AppRegistration appreg = null; string filename = String.Format("{0}.json", instance); if (File.Exists(filename)) { using (var f = new StreamReader(filename)) { var json = f.ReadToEnd(); appreg = JsonConvert.DeserializeObject <Mastonet.Entities.AppRegistration>(json); } appreg.Instance = instance; } if (appreg == null) { // await CreateAppAsync(instance); //ではなく、とりあえず自分で作ったトークンを使う。 var o = new Mastonet.Entities.AppRegistration(); o.Instance = instance; o.Scope = Scope.Read | Scope.Write | Scope.Follow; o.ClientId = "76772cbabef0e50a900fc34f6b44525edea369de8580294bb0bb01b6f684192b"; o.ClientSecret = "8cd0382533a5b345daa25fa63f0feab1af13dc5a8bc3ff115be9e0958bc8e3c5"; appreg = o; string json = JsonConvert.SerializeObject(appreg); using (var f = new StreamWriter(filename)) { f.Write(json); } } if (appreg == null) { throw new System.Security.Authentication.AuthenticationException(); } app = appreg; auth_client.AppRegistration = appreg; }
public Mstdn() { var appregister = new Mastonet.Entities.AppRegistration { Instance = "mstdn.kemono-friends.info", }; var auth = new Mastonet.Entities.Auth { AccessToken = Environment.GetEnvironmentVariable("MSTDN_TOKEN") }; client = new MastodonClient(appregister, auth); }
private void AuthPawooFromFile() { var accessToken = System.IO.File.ReadLines(TokenFilePathPawoo).ToArray()[0]; var appRegistration = new Mastonet.Entities.AppRegistration { Instance = "pawoo.net", ClientId = Properties.Resources.PwClientKey, ClientSecret = Properties.Resources.PwClientSecret }; PawooClient = new Mastonet.MastodonClient(appRegistration, new Mastonet.Entities.Auth { AccessToken = accessToken }); }
/// <summary> /// メニューアイテムの認証→Pawooをクリックした時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void AuthPawooMenuItem_Click(object sender, RoutedEventArgs e) { try { var appRegistration = new Mastonet.Entities.AppRegistration { Instance = "pawoo.net", ClientId = Properties.Resources.PwClientKey, ClientSecret = Properties.Resources.PwClientSecret }; var authClient = new Mastonet.AuthenticationClient(appRegistration); var authWindow = new AuthWindow(authClient.OAuthUrl()); authWindow.ShowDialog(); if (authWindow.isOk) { var accessToken = await authClient.ConnectWithCode(authWindow.pin); PawooClient = new Mastonet.MastodonClient(appRegistration, accessToken); // Save Token using (var sw = new System.IO.StreamWriter(TokenFilePathPawoo)) { sw.WriteLine(accessToken.AccessToken); } // タイムラインのロード foreach (var s in await PawooClient.GetHomeTimeline()) { pawooTimelineStackPanel.Children.Add(new Toot(s)); } } } catch (Mastonet.ServerErrorException ex) { MessageBox.Show(ex.Message, "エラー"); return; } await SetMyAccounts(); }