private async Task Authorize() { dynamic keys = await GetAppCredentials("Facebook"); string clientId = keys.client_id; IDeviceOAuth2Stepwise auth = new DeviceOAuth(EndPointInfo.Facebook, "public_profile", clientId); var info = await auth.StartAuthorization(); var msg = $"Navigate to {info.VerificationUri} \nEnter this code: {info.UserCode}"; Notify.Text = msg; var token = await auth.WaitForUserConsent(info); var defaults = new DynamicRestClientDefaults() { AuthScheme = "Bearer", AuthToken = token.AccessToken }; dynamic client = new DynamicRestClient("https://graph.facebook.com/v2.3/me", defaults); dynamic v = await client.get(fields: "name"); Notify.Text = ""; UserName.Text = v.name; }
private static async Task Go(EndPointInfo endpoint) { var keys = GetAppCredentials(endpoint.Name); IDeviceOAuth2 auth = new DeviceOAuth(endpoint, (string)keys.scopes, (string)keys.client_id, (string)keys.client_secret); auth.WaitingForConfirmation += (o, e) => { Console.CursorLeft = 0; Console.Write(e + " seconds left "); }; auth.PromptUser += (o, e) => { Console.WriteLine(""); Console.WriteLine("Go to this url on any computer:"); Console.WriteLine(e.VerificationUri); Console.WriteLine("And enter this code:"); Console.WriteLine(e.UserCode); Console.WriteLine(""); }; Console.WriteLine("Authenticating..."); try { var token = await auth.Authorize(null); dynamic profile = await auth.GetProfile(token); Console.WriteLine(""); Console.WriteLine("Name = " + profile.name); } catch (AggregateException e) { Console.WriteLine("Error:"); foreach (var inner in e.InnerExceptions) { Console.WriteLine(inner.Message); } } catch (Exception e) { Console.WriteLine("Error:"); Console.WriteLine(e.Message); } }