コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: nickward13/WinPock
        private async Task AuthPocketAsync()
        {
            if (!AuthPocketViaSavedAccessToken())
            {
                pocketClient = new PocketClient(Secrets.PocketAPIConsumerKey);
                Uri          callbackUri  = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
                RequestToken requestToken = await pocketClient.ObtainRequestTokenAsync(
                    callbackUri);

                Uri requestUri = pocketClient.ObtainAuthorizeRequestTokenRedirectUri(requestToken, callbackUri);
                WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateSilentlyAsync(requestUri);

                if (result.ResponseStatus != WebAuthenticationStatus.Success)
                {
                    result = await WebAuthenticationBroker.AuthenticateAsync(
                        WebAuthenticationOptions.None,
                        requestUri);
                }

                AccessToken token = await pocketClient.ObtainAccessTokenAsync(requestToken);

                ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                string tokenString = JsonSerializer.Serialize(token);
                localSettings.Values.Add("accessToken", tokenString);
            }
        }