public async Task <List <Subject> > ReadExpiringSubjectsAsync() { var subjects = new List <Subject>(); var initialApplicationsCollectionPage = await _graphServiceClient.Applications .Request() .Select(app => new { app.KeyCredentials, app.AppId, app.CreatedDateTime, app.DisplayName, app.PasswordCredentials }) .GetAsync(); var iterator = PageIterator <Application> .CreatePageIterator(_graphServiceClient, initialApplicationsCollectionPage, application => { if (!application.PasswordCredentials.Any(_expiringSecretsSelector) && !application.KeyCredentials.Any(_expiringCertificatesSelector)) { return(true); } var appRegistration = new AppRegistration { AppId = application.AppId, DisplayName = application.DisplayName, CreatedDateTime = application.CreatedDateTime }; subjects.AddRange(application.PasswordCredentials.Where(_expiringSecretsSelector).Select(cred => new Subject { DisplayName = cred.DisplayName, Context = cred.Hint, EndDateTime = cred.EndDateTime, StartDateTime = cred.StartDateTime, Id = cred.KeyId.GetValueOrDefault().ToString(), ODataType = cred.ODataType, AppRegistration = appRegistration })); subjects.AddRange(application.KeyCredentials.Where(_expiringCertificatesSelector).Select(key => new Subject { DisplayName = key.DisplayName, Context = Convert.ToBase64String(key.CustomKeyIdentifier), EndDateTime = key.EndDateTime, StartDateTime = key.StartDateTime, Id = key.KeyId.GetValueOrDefault().ToString(), ODataType = key.ODataType, AppRegistration = appRegistration })); return(true); }); await iterator.IterateAsync(); return(subjects); }
public MastdonHelper(MastodonAuthSet mastdonAuthSet) { appRegistration = mastdonAuthSet.AppRegistration; Instance = appRegistration.Instance; acsessToken = mastdonAuthSet.AccessToken; Logger.NLogInfo($"Constructer OK on {Instance}."); }
private static async Task <AppRegistration> _InteractiveRegisterApp() { while (true) { try { Console.WriteLine("# Instance"); Console.Write("url: "); string?url = Console.ReadLine()?.Trim(); if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException(url, "You typed empty instance URL."); } Console.Write("app name: "); string?appName = Console.ReadLine()?.Trim(); if (string.IsNullOrEmpty(appName)) { throw new ArgumentNullException(appName, "You typed empty app name"); } var authClient = new AuthenticationClient(url); AppRegistration appRegistration = await authClient.CreateApp(appName, Scope.Read | Scope.Write | Scope.Follow); return(appRegistration); } catch (Exception ex) { _ProcessUserInputError(ex); } } }
public static Registration ToHerdAppRegistration(this AppRegistration mastodonAppRegistration) => new Registration { ClientId = mastodonAppRegistration.ClientId, ClientSecret = mastodonAppRegistration.ClientSecret, MastodonAppRegistrationID = mastodonAppRegistration.Id.ToString(), Instance = mastodonAppRegistration.Instance };
internal Facebook(bool?enabled, AppRegistration registration, string graphApiVersion, LoginScopes login) { Enabled = enabled; Registration = registration; GraphApiVersion = graphApiVersion; Login = login; }
public void ConfigureApp(AppRegistration appRegistration) { appRegistration .UseSfml <DrawableGameObject <SfmlContext> >() .UseGameLogic() .UseLoop <SimpleLoop>(); }
public AppRegisterResult RegisterApp(AppRegisterDto RegisterUse) { AppRegisterResult result = new AppRegisterResult(); try { AppRegistration appRegistration = new AppRegistration() { UserName = RegisterUse.UserName, FullName = RegisterUse.FullName, pin = RegisterUse.pin, PhoneNumber = RegisterUse.PhoneNumber, FingerPrint = RegisterUse.FingerPrint }; context.Add(appRegistration); context.SaveChanges(); result = new AppRegisterResult() { appRegistration = RegisterUse, StatusCode = (int)HttpStatusCode.OK, Message = HttpStatusCode.OK.ToString() }; } catch (Exception ex) { result = new AppRegisterResult { appRegistration = null, Message = ex.Message, StatusCode = (int)HttpStatusCode.InternalServerError }; } return(result); }
public static AppRegistration UseSfml <TDrawable>(this AppRegistration appRegistration) where TDrawable : IDrawable <SfmlContext> { appRegistration .UseDispatcher <EventDispatcher>() .UseOutput <Graphics2D <TDrawable, SfmlContext, Drawable> >(); return(appRegistration); }
protected AppRegistration GetClientId() { var client_id = File.ReadAllText(client_cred); AppRegistration ap = JsonConvert.DeserializeObject <AppRegistration>(client_id); ap.Instance = base_uri; ap.Scope = Scope.Read | Scope.Write | Scope.Follow; return(ap); }
public MastodonAuthentication(string instanceUri, string accessToken = null) { this.InstanceUri = instanceUri; this.AccessToken = accessToken; this.appRegistration = this.GetAppRegistration(); if (string.IsNullOrEmpty(accessToken)) { // ヘルパがビヘイビアにアタッチされた時 this.OAuthHelper.Attached += (sender, e) => { // すぐさまログインを開始 this.StartOAuthLogin(); }; } else { Task.Run(async() => { try { await this.CreateClientAsync(); this.HasAuthenticated = true; } catch { this.HasAuthenticated = false; } }); } // ブラウザのURIが変わった時 this.OAuthHelper.UriNavigated += async(sender, e) => { try { if (e.Uri.Contains("/oauth/authorize/")) { var paths = e.Uri.Split('/'); this.AccessToken = paths.Last(); await this.CreateClientAsync(); this.OAuthHelper.Hide(); this.HasAuthenticated = true; this.Completed?.Invoke(this, new EventArgs()); } } catch { this.HasAuthenticated = false; this.OnError?.Invoke(this, new EventArgs()); } }; }
public MastodonClient(AppRegistration appRegistration, Auth accessToken, HttpClient client) : base(client) { this.Instance = appRegistration.Instance; this.AppRegistration = appRegistration; this.AuthToken = accessToken; #if NETSTANDARD2_0 this.instanceGetter = new Lazy <Task <Instance> >(this.GetInstance); #endif }
private async void Login_Click(object sender, RoutedEventArgs e) { client = new AuthenticationClient(instanceName.Text); app = await client.CreateApp("Mastonet Sample App", Scope.Read | Scope.Write | Scope.Follow); Properties.Settings.Default.AppInfo = JsonConvert.SerializeObject(app); Properties.Settings.Default.Save(); OpenLogin(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); //Register IoC container var reg = new AppRegistration(); Container = reg.Register(); DependencyResolver.SetResolver(new AutofacDependencyResolver(Container)); GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(Container); }
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); //Register IoC container var reg = new AppRegistration(); Container = reg.Register(); DependencyResolver.SetResolver(new AutofacDependencyResolver(Container)); GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(Container); }
private IAuthenticationClient BuildMastodonAuthenticationClient() { if (_authClient == null) { if (string.IsNullOrWhiteSpace(MastodonHostInstance)) { throw new ArgumentException($"{nameof(MastodonHostInstance)} cannot be null or empty"); } _authClient = AppRegistration == null ? new AuthenticationClient(MastodonHostInstance) : new AuthenticationClient(AppRegistration.ToMastodonAppRegistration()); } return _authClient; }
public void OpenObject(object ObjectToOpen) { // detecting app on Main or Base types var ObjectType = ObjectToOpen?.GetType(); AppRegistration app = null; do { app = this.Registrations.FirstOrDefault(x => x.ObjectType == ObjectType); ObjectType = ObjectType.BaseType; }while (app == null && ObjectType != null); // Open app?.OpenObject(ObjectToOpen); }
//Mastodon側へのログイン処理とストリーム接続ソケットの引き渡し private MastodonClient LoginClient() { var App = new AppRegistration(); var Auth = new Auth(); Console.WriteLine("Enter the Application Password for starting cliMa."); using (StreamReader r = new StreamReader(path)) using (var cryptor = new Cryptor(ReadPassword()))//password input { App.Instance = cryptor.Decode(Convert.FromBase64String(r.ReadLine())); Auth.AccessToken = cryptor.Decode(Convert.FromBase64String(r.ReadLine())); } var client = new MastodonClient(App, Auth); return(client); }
private AppRegistration GetAppRegistration() { var data = InstanceAccessProvider.GetWithInstanceUri(this.InstanceUri); this.StreamingUri = data.StreamingInstance; //var appRegistration = await MastodonClient.CreateApp(this.instanceUrl, ApplicationName, Scope.Follow | Scope.Read | Scope.Write, "http://kmycode.net/"); appRegistration = new AppRegistration { Instance = this.InstanceUri, ClientId = data.ClientId, ClientSecret = data.ClientSecret, Scope = Scope.Follow | Scope.Read | Scope.Write, }; return(appRegistration); }
public static async Task <BotAccess> InteractiveConsoleRegister() { Console.WriteLine("Hello! You look like launching this app first time!"); Console.WriteLine("I'll help you for authorizing your app."); Console.WriteLine(); AppRegistration appReg = await _InteractiveRegisterApp(); var authClient = new AuthenticationClient(appReg); Console.WriteLine(); Auth auth = await _InteractiveLogin(authClient); return(new BotAccess(appReg, auth)); }
private async Task Run() { Dictionary <string, string> uri_list = new Dictionary <string, string>(); var appRegistration = new AppRegistration { Instance = hostName, ClientId = clientId, ClientSecret = clientSecret, Scope = Scope.Read | Scope.Write }; var authClient = new AuthenticationClient(appRegistration); var auth = await authClient.ConnectWithPassword(mail, pass); client = new MastodonClient(appRegistration, auth); var account = await client.GetCurrentUser(); this.userId = account.AccountName; // LTL処理 streaming = client.GetLocalStreaming(); streaming.OnUpdate += (sender, e) => { TextWrite(e.Status); }; //通知処理 homeStreaming = client.GetUserStreaming(); homeStreaming.OnNotification += (sender, e) => { NotificationWrite(e.Notification); }; // メディア処理用 media = new MediaEditClass(ref client); Timer timer = new Timer(); timer.Interval = DefaultValues.TOOTS_INTERVAL; timer.Tick += (object sender, EventArgs e) => { // トゥート回数のリセット tootsCounter = 0; }; timer.Start(); streaming.Start(); homeStreaming.Start(); }
private IMastodonClient GetOrCreateMastodonClient() { if (_mastodonClient == null) { if (AppRegistration == null) { throw new ArgumentNullException(nameof(AppRegistration)); } if (UserMastodonConnectionDetails == null) { throw new ArgumentNullException(nameof(UserMastodonConnectionDetails)); } _mastodonClient = new MastodonClient(AppRegistration.ToMastodonAppRegistration(), UserMastodonConnectionDetails.ToMastodonAuth()); } return _mastodonClient; }
public void CheckLogin() { if (!String.IsNullOrEmpty(Properties.Settings.Default.AppInfo)) { app = JsonConvert.DeserializeObject <AppRegistration>(Properties.Settings.Default.AppInfo); client = new AuthenticationClient(app); if (!String.IsNullOrEmpty(Properties.Settings.Default.AuthToken)) { auth = JsonConvert.DeserializeObject <Auth>(Properties.Settings.Default.AuthToken); Logged?.Invoke(this, new LoggedEventArgs(app, auth)); } else { OpenLogin(); } } }
private async void OnAppRegistAsync(object sender, RoutedEventArgs e) { var progdiag = await this.ShowProgressAsync("読み込み中...", "認証の準備をしています。しばらくお待ちください。"); try { authClient = new AuthenticationClient(InstanceNameTextBox.Text); registeredApp = await authClient.CreateApp("なうぷれTunes", Scope.Read | Scope.Write); WindowTab.SelectedIndex = 1; } catch (Exception ex) { await this.ShowMessageAsync("エラー", $"何らかのエラーで認証を開始することが出来ませんでした。インスタンス名をもう一度確認してください。\n\n{ex}"); } finally { await progdiag.CloseAsync(); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var appRegistration = new AppRegistration(); var authToken = new Auth(); var jsonObject = JObject.Load(reader); appRegistration.ClientId = jsonObject["AppRegistration"]["ClientId"].Value <string>(); appRegistration.ClientSecret = jsonObject["AppRegistration"]["ClientSecret"].Value <string>(); appRegistration.Id = jsonObject["AppRegistration"]["Id"].Value <long>(); appRegistration.Instance = jsonObject["AppRegistration"]["Instance"].Value <string>(); appRegistration.RedirectUri = jsonObject["AppRegistration"]["RedirectUri"].Value <string>(); var scope = jsonObject["AppRegistration"]["Scope"].Value <long>(); appRegistration.Scope = (Scope)Enum.ToObject(typeof(Scope), scope); authToken.AccessToken = jsonObject["AuthToken"]["AccessToken"].Value <string>(); authToken.TokenType = jsonObject["AuthToken"]["TokenType"].Value <string>(); authToken.Scope = jsonObject["AuthToken"]["Scope"].Value <string>(); authToken.CreatedAt = jsonObject["AuthToken"]["CreatedAt"].Value <string>(); return(new MastodonClient(appRegistration, authToken)); }
public async Task <IHttpActionResult> Index([FromBody] AppRegistration reg) { return(await Task <IHttpActionResult> .Factory.StartNew(() => { try { var app = dataLayer.AddApplication(new application { display_name = reg.display_name, application_id = NewGuidString(), secret = NewGuidString() }); return Ok(new RegisterAppResult { display_name = app.display_name, application_id = app.application_id, secret = app.secret }); } catch (Exception ex) { return BadRequest(ex.Message); } })); }
AppRegistration AppRegistrateLogic(string fileName = @".\AppRegistration.xml") { var appreg = new AppRegistration(); if (File.Exists(fileName)) { Console.WriteLine($"\"{fileName}\"を読み込みます。"); var serializer = new XmlSerializer(typeof(AppRegistration)); using (var sr = new StreamReader(fileName)) { appreg = (AppRegistration)serializer.Deserialize(sr); } } else { Console.WriteLine($"\"{fileName}\"が存在しません。作成します。設定値を編集して保存してください。"); appreg = new AppRegistration { Instance = "Instance is Here! (ex: example.com)", ClientId = "Client_id is Here!", ClientSecret = "Client_secret is Here!", Scope = Scope.Follow | Scope.Read | Scope.Write }; var serializer = new XmlSerializer(typeof(AppRegistration)); using (var sw = new StreamWriter(fileName)) { serializer.Serialize(sw, appreg); } } Console.WriteLine($"Instance: {appreg.Instance}"); Console.WriteLine($"ClientID: {appreg.ClientId}"); Console.WriteLine($"ClientSecret: {appreg.ClientSecret}"); return(appreg); }
public AuthenticationClient(AppRegistration app, HttpClient client) : base(client) { this.Instance = app.Instance; this.AppRegistration = app; }
public AuthenticationClient(AppRegistration app) : this(app, DefaultHttpClient.Instance) { }
public AuthenticationClient(AppRegistration app) { this.Instance = app.Instance; this.AppRegistration = app; }
public MainModel(AppRegistration app, Auth auth) { Client = new MastodonClient(app, auth); InitModel(); }