Example #1
0
        public void ShowWindow()
        {
            var url    = $"https://mamot.fr/oauth/authorize?scope=read%20write%20follow&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=cc83c9ebbc2e817d6c71dc0c82f2c404e340ab7e96e62525526fe5d1c3e5fa9a";
            var window = new MastodonOauth(url);

            window.ShowDialog();
        }
Example #2
0
        public async Task <string> GetAccessTokenAsync(AppInfoWrapper appInfo, string mastodonName, string mastodonInstance)
        {
            using (var authHandler = new AuthHandler(mastodonInstance))
            {
                //Get Oauth Code
                var oauthCodeUrl = authHandler.GetOauthCodeUrl(appInfo.client_id, AppScopeEnum.Read | AppScopeEnum.Write | AppScopeEnum.Follow);

                var code = "";
                var t    = Task.Factory.StartNew
                           (
                    () =>
                {
                    var mastodonWindows = new MastodonOauth(oauthCodeUrl);
                    mastodonWindows.ShowDialog();
                    code = mastodonWindows.Code;
                },
                    CancellationToken.None,
                    TaskCreationOptions.None,
                    TaskScheduler.FromCurrentSynchronizationContext()
                           );

                t.Wait();

                //Get token
                var token = await authHandler.GetTokenInfoAsync(appInfo.client_id, appInfo.client_secret, code);

                return(token.access_token);
            }
        }