private async Task MiAuthAsync()
        {
            uuid = Guid.NewGuid().ToString();

            var url = $"https://{Url.Value}/miauth/{uuid}?"
                      + "name=Groundpolis+Mobile"
                      + $"&callback={HttpUtility.UrlEncode(Const.MIAUTH_CALLBACK)}"
                      + $"&permission={string.Join(",", Groundpolis.Permission)}";

            // MVVM の流儀に反するけど、しらねー
            try
            {
                await WebAuthenticator.AuthenticateAsync(new Uri(url), new Uri(Const.MIAUTH_CALLBACK));
            }
            catch (Exception)
            {
                Error.Value    = "は?エラーやぞ";
                IsLoaded.Value = true;
                IsBusy.Value   = false;
                return;
            }

            IsLoaded.Value = true;

            IsBusy.Value = true;
            var miauthUrl = $"https://{Url.Value}/api/miauth/{uuid}/check";
            var res       = await Http.PostAsync(miauthUrl, new StringContent(""));

            var json = await res.Content.ReadAsStringAsync();

            var status = JsonConvert.DeserializeObject <MiAuthStatus>(json);

            if (status.Ok)
            {
                await Groundpolis.SignInAsync(status.Token, Url.Value);

                while (Root.Navigation.ModalStack.Count > 0)
                {
                    await Root.Navigation.PopModalAsync();
                }
            }
            else
            {
                Error.Value = "認証に失敗しました";
            }
        }
Esempio n. 2
0
        private async Task MiAuthAsync(JoinMisskeyInstanceViewModel vm)
        {
            var uuid = Guid.NewGuid().ToString();

            var url = $"https://{vm.Url.Value}/miauth/{uuid}?"
                      + "name=Groundpolis+Mobile"
                      + $"&callback={HttpUtility.UrlEncode(Const.MIAUTH_CALLBACK)}"
                      + $"&permission={string.Join(",", Groundpolis.Permission)}";

            // MVVM の流儀に反するけど、しらねー
            try
            {
                await WebAuthenticator.AuthenticateAsync(new Uri(url), new Uri(Const.MIAUTH_CALLBACK));
            }
            catch (Exception)
            {
                return;
            }

            var miauthUrl = $"https://{vm.Url.Value}/api/miauth/{uuid}/check";
            var res       = await Http.PostAsync(miauthUrl, new StringContent(""));

            var json = await res.Content.ReadAsStringAsync();

            var status = JsonConvert.DeserializeObject <MiAuthStatus>(json);

            if (status.Ok)
            {
                await Groundpolis.SignInAsync(status.Token, vm.Url.Value);

                while (Root.Navigation.ModalStack.Count > 0)
                {
                    await Root.Navigation.PopModalAsync();
                }
            }
            else
            {
                await Root.DisplayAlert("認証に失敗しました", "もう一度やり直してください。", "OK");
            }
        }