async private void Page_Loaded(object sender, RoutedEventArgs e) { var location = Windows.ApplicationModel.Package.Current.InstalledLocation; coinbase = JToken.FromObject(""); try { var file = await location.GetFileAsync("APIKeys.json"); string json = await FileIO.ReadTextAsync(file); #if DEBUG coinbase = JObject.Parse(json).SelectToken("coinbase_sandbox"); #else coinbase = JObject.Parse(json).SelectToken("coinbase"); #endif } catch (Exception) { NavigationTransitionInfo transition = new DrillInNavigationTransitionInfo(); this.Frame.Navigate(typeof(MainPage), "Coinbase", transition); } #if !TESTLOGIN && DEBUG NavigateToWallet((string)coinbase["developer_access_token"]); #endif Uri coinBaseAuthURL = new Uri(string.Format("{0}oauth/authorize?response_type=code&client_id={1}&redirect_uri={2}&scope=wallet:accounts:read", coinbase["url"], coinbase["client_id"], coinbase["redirect"])); LoginWebView.Navigate(coinBaseAuthURL); }
private async Task ConnectAccountAsync(ServiceType serviceType) { // Generate State (for security) _stateVerification = new Random().Next(0, 100000000).ToString("D8"); _loginService = serviceType; // Create the URI var connectUri = string.Empty; switch (serviceType) { case ServiceType.SoundCloud: connectUri = $"https://soundcloud.com/connect?scope=non-expiring&client_id={ApiKeyService.SoundCloudClientId}&response_type=code&display=popup&redirect_uri={_appCallback}&state={_stateVerification}"; break; case ServiceType.Fanburst: connectUri = $"https://fanburst.com/oauth/authorize?client_id={ApiKeyService.FanburstClientId}&response_type=code&redirect_uri={_appCallback}&state={_stateVerification}"; break; } // Clear any webview cache await WebView.ClearTemporaryWebDataAsync(); // Show the web view and navigate to the connect URI LoginWebView.Visibility = Visibility.Visible; LoginWebView.Navigate(new Uri(connectUri)); }
/// <summary> /// /// </summary> /// <param name="service"></param> /// <param name="isRemoteConnect"></param> /// <param name="loginCode"></param> public LoginDialog(ServiceType service, bool isRemoteConnect = false, string loginCode = "") { // Set the login service type _loginService = service; _stateVerification = new Random().Next(0, 100000000).ToString("D8"); _isRemoteConnect = isRemoteConnect; _loginCode = loginCode; // Load the XAML page InitializeComponent(); // Loading event handlers LoginWebView.NavigationStarting += (sender, args) => { LoadingSection.Visibility = Visibility.Visible; }; LoginWebView.NavigationCompleted += (sender, args) => { LoadingSection.Visibility = Visibility.Collapsed; }; // Handle new window requests, if a new window is requested, just navigate on the // current page. LoginWebView.NewWindowRequested += (view, eventArgs) => { eventArgs.Handled = true; LoginWebView.Navigate(eventArgs.Uri); }; // Set the callback var appCallback = Uri.EscapeUriString("http://localhost/soundbyte"); // Create the URI string connectUri; switch (_loginService) { case ServiceType.SoundCloud: case ServiceType.SoundCloudV2: connectUri = $"https://soundcloud.com/connect?scope=non-expiring&client_id={AppKeysHelper.SoundCloudClientId}&response_type=code&display=popup&redirect_uri={appCallback}&state={_stateVerification}"; break; case ServiceType.Fanburst: connectUri = $"https://fanburst.com/oauth/authorize?client_id={AppKeysHelper.FanburstClientId}&response_type=code&redirect_uri={appCallback}&state={_stateVerification}&display=popup"; break; case ServiceType.YouTube: connectUri = $"https://accounts.google.com/o/oauth2/v2/auth?client_id={AppKeysHelper.YouTubeLoginClientId}&redirect_uri={appCallback}&response_type=code&state={_stateVerification}&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube"; break; case ServiceType.SoundByte: connectUri = $"https://soundbytemedia.com/connect/authorize?client_id={AppKeysHelper.SoundByteClientId}&response_type=code&redirect_uri={appCallback}&state={_stateVerification}&scope=api%20offline_access"; break; default: throw new ArgumentOutOfRangeException(); } // Show the web view and navigate to the connect URI LoginWebView.Visibility = Visibility.Visible; LoginWebView.Navigate(new Uri(connectUri)); }
protected override void OnCreate(object parameter) { base.OnCreate(parameter); var requri = new Uri("https://m.weibo.cn/login?backURL=https%253A%252F%252Fm.weibo.cn%252F"); LoginWebView.NavigationCompleted += LoginWebViewOnNavigationCompleted; LoginWebView.Navigate(requri); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Clear the cache await WebView.ClearTemporaryWebDataAsync(); // Navigate to the connect url LoginWebView.Navigate(new Uri(Vm.AuthenticationDetails.ConnectUrl)); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { var args = (AccountViewParams)e.Parameter; // Set the login service type _loginService = args.Service; _stateVerification = new Random().Next(0, 100000000).ToString("D8"); // Create the URI string connectUri; // Hide new login system for now AccountV3Section.Visibility = Visibility.Collapsed; switch (_loginService) { //soundbyte://authorization/lastfm case ServiceTypes.SoundCloud: case ServiceTypes.SoundCloudV2: connectUri = $"https://soundcloud.com/connect?scope=non-expiring&client_id={AppKeys.SoundCloudClientId}&response_type=code&display=popup&redirect_uri={AppKeys.AppLegacyCallback}&state={_stateVerification}"; break; case ServiceTypes.YouTube: connectUri = $"https://accounts.google.com/o/oauth2/v2/auth?client_id={AppKeys.YouTubeLoginClientId}&redirect_uri={AppKeys.AppLegacyCallback}&response_type=code&state={_stateVerification}&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube"; break; case ServiceTypes.SoundByte: connectUri = $"https://soundbytemedia.com/connect/authorize?client_id={AppKeys.SoundByteClientId}&response_type=code&redirect_uri={AppKeys.AppLegacyCallback}&state={_stateVerification}&scope=api%20offline_access"; break; default: throw new ArgumentOutOfRangeException(); } //// Only these services are supported at the moment //if (_loginService == ServiceType.SoundByte // || _loginService == ServiceType.Spotify) //{ // AccountV3Section.Visibility = Visibility.Visible; // await Launcher.LaunchUriAsync(new Uri(connectUri)); //} //else //{ // Clear cache await WebView.ClearTemporaryWebDataAsync(); // Show the web view and navigate to the connect URI LoginWebView.Visibility = Visibility.Visible; LoginWebView.Navigate(new Uri(connectUri)); // } }
public AccountView() { InitializeComponent(); // Loading event handlers LoginWebView.NavigationStarting += (sender, a) => { LoadingSection.Visibility = Visibility.Visible; }; LoginWebView.NavigationCompleted += (sender, a) => { LoadingSection.Visibility = Visibility.Collapsed; }; // Handle new window requests, if a new window is requested, just navigate on the // current page. LoginWebView.NewWindowRequested += (view, eventArgs) => { eventArgs.Handled = true; LoginWebView.Navigate(eventArgs.Uri); }; }
private void LoginWebView_OnLoaded(object sender, RoutedEventArgs e) { using (var db = new CacheDbContext()) { if (db.SessionInfo.Any()) { var sessionInfo = db.SessionInfo.First(); if (!string.IsNullOrWhiteSpace(sessionInfo.AccessToken)) { AuthWithKnownToken(sessionInfo); return; } } } LoginWebView.Navigate(new Uri( $"https://oauth.vk.com/authorize?client_id={VkConstants.AppId}&display=page&scope={VkConstants.AppScope}&redirect_uri=https://oauth.vk.com/blank.html&response_type=token&v=5.103&state=success" )); }
public AccountView() { // Load the XAML page InitializeComponent(); LoginWebView.NavigationStarting += (sender, args) => { LoadingSection.Visibility = Visibility.Visible; }; LoginWebView.NavigationCompleted += (sender, args) => { LoadingSection.Visibility = Visibility.Collapsed; }; // Handle new window requests, if a new window is requested, just navigate on the // current page. LoginWebView.NewWindowRequested += (view, eventArgs) => { eventArgs.Handled = true; LoginWebView.Navigate(eventArgs.Uri); }; // Set the callback _appCallback = Uri.EscapeUriString("http://localhost/soundbyte"); }
public LoginView() { this.InitializeComponent(); DataContext = ViewModel; //Values can be found at https://github.com/settings/applications _clientId = ApiKeysManager.GithubClientId; _clientSecret = ApiKeysManager.GithubClientSecret; _client = new GitHubClient(new ProductHeaderValue("gitit")); while (ApiKeysManager.GithubClientId == null) { } var loginRequest = new OauthLoginRequest(_clientId) { Scopes = { "user", "notifications", "repo", "gist", "read:org" } }; var oAuthLoginUrl = _client.Oauth.GetGitHubLoginUrl(loginRequest); LoginWebView.Navigate(oAuthLoginUrl); LoginWebView.NavigationCompleted += LoginWebViewOnNavigationCompleted; }
private async void LoginWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { if (args.Uri.OriginalString == "https://www.coolapk.com/") { var dialog = new ContentDialog { Title = "是否登录完成", Content = "检测到你可能已经完成登录", IsPrimaryButtonEnabled = true, IsSecondaryButtonEnabled = true, PrimaryButtonText = "验证状态", SecondaryButtonText = "重试" }; var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { AppBarButton_Tapped(null, null); } else if (result == ContentDialogResult.Secondary) { LoginWebView.Navigate(new Uri("https://account.coolapk.com/")); } } }
public AccountView() { // Load the XAML page InitializeComponent(); LoginWebView.NavigationStarting += (sender, args) => { LoadingSection.Visibility = Visibility.Visible; }; LoginWebView.NavigationCompleted += (sender, args) => { LoadingSection.Visibility = Visibility.Collapsed; }; // On disconnect and connect events refresh the UI SoundByteV3Service.Current.OnServiceConnected += (type, token) => RefreshUi(); SoundByteV3Service.Current.OnServiceDisconnected += type => RefreshUi(); // Handle new window requests, if a new window is requested, just navigate on the // current page. LoginWebView.NewWindowRequested += (view, eventArgs) => { eventArgs.Handled = true; LoginWebView.Navigate(eventArgs.Uri); }; // Set the callback _appCallback = Uri.EscapeUriString("http://localhost/soundbyte"); }
protected override void OnNavigatedTo(NavigationEventArgs e) { LoginWebView.Navigate(new Uri("https://api.soundcloud.com/connect?client_id=1d57801f1cc71e123c1b9c58aa45c8e7&redirect_uri=&response_type=code_and_token")); }
public Login() { this.InitializeComponent(); LoginWebView.Navigate(new Uri(_login_url_jumpHome)); }
private void LoginWebView_OnLoaded(object sender, RoutedEventArgs e) { LoginWebView.Navigate(new Uri( $"https://oauth.vk.com/authorize?client_id={VkConstants.AppId}&display=page&scope={VkConstants.AppScope}&redirect_uri=https://oauth.vk.com/blank.html&response_type=token&v=5.103&state=success" )); }
private void Dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { LoginWebView.Navigate(new Uri("https://account.coolapk.com/")); }
private void AppBarButtonClearLoginState_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { App.AppViewModel.Logout(); LoginWebView.Navigate(new Uri("https://account.coolapk.com/")); }
protected override void OnNavigatedTo(NavigationEventArgs e) { // Get the account type var accountType = e.Parameter?.ToString(); if (string.IsNullOrEmpty(accountType)) { accountType = "soundcloud"; } TelemetryService.Current.TrackPage("Login Page"); // Generate State (for security) var stateVerification = new Random().Next(0, 100000000).ToString("D8"); // Generate Application callback URI var callback = Uri.EscapeUriString("http://localhost/soundbyte"); // Create the URI var connectUri = new Uri(accountType == "soundcloud" ? $"https://soundcloud.com/connect?scope=non-expiring&client_id={Common.ServiceKeys.SoundCloudClientId}&response_type=code&display=popup&redirect_uri={callback}&state={stateVerification}" : $"https://fanburst.com/oauth/authorize?client_id={Common.ServiceKeys.FanburstClientId}&response_type=code&redirect_uri={callback}&state={stateVerification}"); // Navigate to the connect URI LoginWebView.Navigate(connectUri); // Handle new window requests, if a new window is requested, just navigate on the // current page. LoginWebView.NewWindowRequested += (view, eventArgs) => { eventArgs.Handled = true; LoginWebView.Navigate(eventArgs.Uri); }; // Called when the webview is going to navigate to another // Uri. LoginWebView.NavigationStarting += async(view, eventArgs) => { // If we are navigating to google, let the user know that google login is not supported if (eventArgs.Uri.Host == "accounts.google.com") { // Cancel the page load and hide the loading panel eventArgs.Cancel = true; LoadingSection.Visibility = Visibility.Collapsed; TelemetryService.Current.TrackEvent("Google Sign in Attempt"); await new MessageDialog("Google Account sign in is not supported. Please instead signin with a Facebook or SoundCloud account.", "Sign in Error").ShowAsync(); } // We worry about localhost addresses are they are directed towards us. if (eventArgs.Uri.Host == "localhost") { // Cancel the navigation, (as localhost does not exist). eventArgs.Cancel = true; // Parse the URL for work // ReSharper disable once CollectionNeverUpdated.Local var parser = new QueryParameterCollection(eventArgs.Uri); // First we just check that the state equals (to make sure the url was not hijacked) var state = parser.FirstOrDefault(x => x.Key == "state").Value; // The state does not match if (string.IsNullOrEmpty(state) || state.TrimEnd('#') != stateVerification) { // Display the error to the user await new MessageDialog("State Verfication Failed. This could be caused by another process intercepting the SoundByte login procedure. Sigin has been canceled to protect your privacy.", "Sign in Error").ShowAsync(); TelemetryService.Current.TrackEvent("State Verfication Failed"); // Close LoadingSection.Visibility = Visibility.Collapsed; App.GoBack(); return; } // We have an error if (parser.FirstOrDefault(x => x.Key == "error").Value != null) { var type = parser.FirstOrDefault(x => x.Key == "error").Value; var reason = parser.FirstOrDefault(x => x.Key == "error_description").Value; // The user denied the request if (type == "access_denied") { LoadingSection.Visibility = Visibility.Collapsed; App.GoBack(); return; } // Display the error to the user await new MessageDialog(reason, "Sign in Error").ShowAsync(); // Close LoadingSection.Visibility = Visibility.Collapsed; App.GoBack(); return; } // Get the code from the url if (parser.FirstOrDefault(x => x.Key == "code").Value != null) { var code = parser.FirstOrDefault(x => x.Key == "code").Value; // Create a http client to get the token using (var httpClient = new HttpClient()) { // Set the user agent string httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("SoundByte", Package.Current.Id.Version.Major + "." + Package.Current.Id.Version.Minor + "." + Package.Current.Id.Version.Build)); // Get all the params var parameters = new Dictionary <string, string> { { "client_id", accountType == "soundcloud" ? Common.ServiceKeys.SoundCloudClientId : Common.ServiceKeys.FanburstClientId }, { "client_secret", accountType == "soundcloud" ? Common.ServiceKeys.SoundCloudClientSecret : Common.ServiceKeys.FanburstClientSecret }, { "grant_type", "authorization_code" }, { "redirect_uri", callback.ToString() }, { "code", code } }; var encodedContent = new FormUrlEncodedContent(parameters); // Post to the soundcloud API using (var postQuery = await httpClient.PostAsync(accountType == "soundcloud" ? "https://api.soundcloud.com/oauth2/token" : "https://fanburst.com/oauth/token", encodedContent)) { // Check if the post was successful if (postQuery.IsSuccessStatusCode) { // Get the stream using (var stream = await postQuery.Content.ReadAsStreamAsync()) { // Read the stream using (var streamReader = new StreamReader(stream)) { // Get the text from the stream using (var textReader = new JsonTextReader(streamReader)) { // Used to get the data from JSON var serializer = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore }; // Get the class from the json var response = serializer.Deserialize <SoundByteService.Token>(textReader); // Create the password vault var vault = new PasswordVault(); if (accountType == "soundcloud") { // Store the values in the vault vault.Add(new PasswordCredential("SoundByte.SoundCloud", "Token", response.AccessToken.ToString())); vault.Add(new PasswordCredential("SoundByte.SoundCloud", "Scope", response.Scope.ToString())); } else { // Store the values in the vault vault.Add(new PasswordCredential("SoundByte.FanBurst", "Token", response.AccessToken.ToString())); } LoadingSection.Visibility = Visibility.Collapsed; TelemetryService.Current.TrackEvent("Login Successful", new Dictionary <string, string>() { { "service", accountType } }); App.NavigateTo(typeof(HomeView)); } } } } else { // Display the error to the user await new MessageDialog("Token Error. Try again later.", "Sign in Error").ShowAsync(); // Close LoadingSection.Visibility = Visibility.Collapsed; App.GoBack(); } } } } } }; }
public void NavigateWebView(Uri uri) { LoginWebView.Navigate(uri); }