private static async Task Run() { var client = new CopyClient( new Config { CallbackUrl = "https://www.yourapp.com/Copy", ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret, //Token = Token, //TokenSecret = TokenSecret }); // Perform authorization (alternatively, provide a Token and TokenSecret in the Config object passed to CopyClient await Authorize(client); // Retrieve information on the logged-in user var user = await client.UserManager.GetUserAsync(); // Retrieve the root folder of the logged-in user var rootFolder = await client.GetRootFolder(); foreach (var child in rootFolder.Children) { var childInfo = await client.FileSystemManager.GetFileSystemInformationAsync(child.Id); } }
public async Task <ActionResult> About() { ViewBag.Message = "Your app description page."; string verifier = Request.QueryString["oauth_verifier"]; if (!string.IsNullOrEmpty(verifier)) { Authentication.CopyAuth copyConfig = (Authentication.CopyAuth)Session["copyConfig"]; CopyClient copyClient = await copyConfig.GetAccessTokenAsync(verifier); Session.Add("copyClient", copyClient); FileSystem rootFolder = await copyClient.GetRootFolder(); } else if (Session["copyClient"] != null) { //CopyClient copyClient = (CopyClient) Session["copyClient"]; //FileSystem rootFolder = await copyClient.GetRootFolder(); } return(View()); }
private async void AfterAuthenticate(CopyClient copyClient) { User user = await copyClient.UserManager.GetUserAsync(); UserText.Text = string.Format("{0} {1} {2}", user.FirstName, user.LastName, user.Email); Oauth.Visibility = Visibility.Collapsed; UserDetails.Visibility = Visibility.Visible; }
private async void AfterAuthenticate(CopyClient copyClient) { User user = await copyClient.UserManager.GetUserAsync(); UserText.Text = string.Format("{0} {1} {2}", user.FirstName, user.LastName, user.Email); Oauth.Visibility = Visibility.Collapsed; UserDetails.Visibility = Visibility.Visible; }
private static Task <bool> Authorize(CopyClient client) { var completion = new TaskCompletionSource <bool>(); // Get request token var requestToken = client.Authorization.GetRequestTokenAsync().Result; string oauth_token = null; string oauth_verifier = null; var authUriString = requestToken.AuthCodeUri.ToString(); // Navigate user to the returned Authorization Url var browser = new BrowserWindow(); browser.Navigating += (sender, eventArgs) => Console.WriteLine("Navigating: " + eventArgs.Uri); browser.Navigated += (sender, eventArgs) => { // If user logged in, and returned the OAuth Verifier, retrieve that information and close browser var uri = eventArgs.Uri.OriginalString; if (uri.Contains("oauth_verifier=")) { var query = uri.Split('?')[1]; string[] kvpairs = query.Split('&'); Dictionary <string, string> parameters = kvpairs.Select(pair => pair.Split('=')).ToDictionary(kv => kv[0], kv => kv[1]); oauth_token = parameters["oauth_token"]; oauth_verifier = parameters["oauth_verifier"]; Console.WriteLine("Authorized: " + oauth_verifier); browser.Close(); } else { Console.WriteLine("Navigated: " + eventArgs.Uri); } }; browser.Show(authUriString); // If we got the OAuth Verifier, convert it to an Access Token, and complete Authorization if (oauth_token != null && oauth_verifier != null) { client.Authorization.GetAccessTokenAsync(oauth_verifier).Wait(); completion.SetResult(true); } else { completion.SetException(new Exception("Failed to authorize")); } return(completion.Task); }
public async Task <ActionResult> Contact() { ViewBag.Message = "Your contact page."; CopyClient copyClient = (CopyClient)Session["copyClient"]; if (copyClient != null) { User user = await copyClient.UserManager.GetUserAsync(); } return(View()); }
public async Task <ActionResult> Upload(HttpPostedFileBase fileUpload) { byte[] fileBytes; using (Stream inputStream = fileUpload.InputStream) { MemoryStream memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); fileBytes = memoryStream.ToArray(); } CopyClient copyClient = (CopyClient)Session["copyClient"]; bool b = await copyClient.FileSystemManager.UploadNewFileAsync("/copy", fileUpload.FileName, fileBytes, false); return(View("About")); }
public static async Task <CopyClient> Login(string account, string code) { if (string.IsNullOrEmpty(account)) { throw new ArgumentNullException(nameof(account)); } var client = new CopyClient(new Config() { ConsumerKey = Secrets.CONSUMER_KEY, ConsumerSecret = Secrets.CONSUMER_SECRET, CallbackUrl = COPY_LOGIN_DESKTOP_URI }); var refreshToken = LoadRefreshToken(account); var tokens = refreshToken ?? (!string.IsNullOrEmpty(code) ? SplitToken(code) : default(Tuple <string, string>)); if (tokens != null) { client.Config.Token = tokens.Item1; client.Config.TokenSecret = tokens.Item2; } else { var requestToken = await client.Authorization.GetRequestTokenAsync(); tokens = GetAuthCode(account, requestToken.AuthCodeUri, new Uri(COPY_LOGIN_DESKTOP_URI)); if (string.IsNullOrEmpty(tokens.Item1) || string.IsNullOrEmpty(tokens.Item2)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.RetrieveAuthenticationCodeFromUri, requestToken.AuthCodeUri.ToString())); } await client.Authorization.GetAccessTokenAsync(tokens.Item2); tokens = new Tuple <string, string>(client.Config.Token, client.Config.TokenSecret); } SaveRefreshToken(account, tokens); return(client); }
// Sample code for building a localized ApplicationBar //private void BuildLocalizedApplicationBar() //{ // // Set the page's ApplicationBar to a new instance of ApplicationBar. // ApplicationBar = new ApplicationBar(); // // Create a new button and set the text value to the localized string from AppResources. // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); // appBarButton.Text = AppResources.AppBarButtonText; // ApplicationBar.Buttons.Add(appBarButton); // // Create a new menu item with the localized string from AppResources. // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); // ApplicationBar.MenuItems.Add(appBarMenuItem); //} private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { if (_appSettings.Contains("authenticated")) { Oauth.Visibility = Visibility.Collapsed; UserDetails.Visibility = Visibility.Visible; } else { Oauth.VerifiedCodeReceived += async(s, ec) => { OAuth2Sample auth = s as OAuth2Sample; if (auth != null) { copyClient = await copyConfig.GetAccessTokenAsync(auth.VerifierCode); Dispatcher.BeginInvoke(new Action <CopyClient>(AfterAuthenticate), copyClient); } }; Scope scope = new Scope() { Profile = new ProfilePermission() { Read = true, Write = true } }; copyConfig = new Authentication.CopyAuth("http://copysdk", "cIAKv1kFCwXn2izGsMl8vZmfpfBcJSv1", "vNY1oLTr2WieLYxgCA6tDgdfCS1zTRA2IMzhmQLoQOS7nmIK", scope); await copyConfig.GetRequestTokenAsync(); Oauth.Visibility = Visibility.Visible; AuthenticateBtn.Visibility = Visibility.Collapsed; Oauth.GetVerifierCode(copyConfig.AuthCodeUri, new Uri(copyConfig.CallbackURL)); } }
// Sample code for building a localized ApplicationBar //private void BuildLocalizedApplicationBar() //{ // // Set the page's ApplicationBar to a new instance of ApplicationBar. // ApplicationBar = new ApplicationBar(); // // Create a new button and set the text value to the localized string from AppResources. // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); // appBarButton.Text = AppResources.AppBarButtonText; // ApplicationBar.Buttons.Add(appBarButton); // // Create a new menu item with the localized string from AppResources. // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); // ApplicationBar.MenuItems.Add(appBarMenuItem); //} private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { if (_appSettings.Contains("authenticated")) { Oauth.Visibility = Visibility.Collapsed; UserDetails.Visibility = Visibility.Visible; } else { Oauth.VerifiedCodeReceived += async (s, ec) => { OAuth2Sample auth = s as OAuth2Sample; if (auth != null) { copyClient = await copyConfig.GetAccessTokenAsync(auth.VerifierCode); Dispatcher.BeginInvoke(new Action<CopyClient>(AfterAuthenticate), copyClient); } }; Scope scope = new Scope() { Profile = new ProfilePermission() { Read = true, Write = true } }; copyConfig = new Authentication.CopyAuth("http://copysdk", "cIAKv1kFCwXn2izGsMl8vZmfpfBcJSv1", "vNY1oLTr2WieLYxgCA6tDgdfCS1zTRA2IMzhmQLoQOS7nmIK", scope); await copyConfig.GetRequestTokenAsync(); Oauth.Visibility = Visibility.Visible; AuthenticateBtn.Visibility = Visibility.Collapsed; Oauth.GetVerifierCode(copyConfig.AuthCodeUri, new Uri(copyConfig.CallbackURL)); } }
public static async Task<CopyClient> Login(string account, string code) { if (string.IsNullOrEmpty(account)) throw new ArgumentNullException(nameof(account)); var client = new CopyClient(new Config() { ConsumerKey = Secrets.CONSUMER_KEY, ConsumerSecret = Secrets.CONSUMER_SECRET, CallbackUrl = COPY_LOGIN_DESKTOP_URI }); var refreshToken = LoadRefreshToken(account); var tokens = refreshToken ?? (!string.IsNullOrEmpty(code) ? SplitToken(code) : default(Tuple<string, string>)); if (tokens != null) { client.Config.Token = tokens.Item1; client.Config.TokenSecret = tokens.Item2; } else { var requestToken = await client.Authorization.GetRequestTokenAsync(); tokens = GetAuthCode(account, requestToken.AuthCodeUri, new Uri(COPY_LOGIN_DESKTOP_URI)); if (string.IsNullOrEmpty(tokens.Item1) || string.IsNullOrEmpty(tokens.Item2)) throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.RetrieveAuthenticationCodeFromUri, requestToken.AuthCodeUri.ToString())); await client.Authorization.GetAccessTokenAsync(tokens.Item2); tokens = new Tuple<string, string>(client.Config.Token, client.Config.TokenSecret); } SaveRefreshToken(account, tokens); return client; }
public CopyContext(CopyClient client) { Client = client; }
public CopyContext(CopyClient client) { Client = client; }