public void queryUserInfo(Action <bool> callback) { var request = new Xamarin.Auth.OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, getFacebookToken()); request.GetResponseAsync().ContinueWith(t => { Device.BeginInvokeOnMainThread(() => { System.Diagnostics.Debug.WriteLine("--- auth result:" + t.IsFaulted); if (t.IsFaulted) { callback(false); } else { callback(true); } }); }); }
public static void Initilize(string clientId) { if (clientId.IsEmpty()) { Log.For(typeof(Google)).Error("Please set the ClientId by calling Initilize method first!"); return; } Auth = new Xamarin.Auth.OAuth2Authenticator( clientId, "", "openid profile email", new Uri(AUTH_END_POINT), new Uri($"com.googleusercontent.apps.{clientId.Remove(".apps.googleusercontent.com")}:/oauth2redirect"), new Uri(TOKEN_END_POINT), null, true) { AllowCancel = true }; Auth.Completed += async(s, args) => { if (args.IsAuthenticated) { var request = new Xamarin.Auth.OAuth2Request("GET", new Uri(USER_INFO_END_POINT), null, args.Account); var response = await request.GetResponseAsync(); var accountStr = await response.GetResponseTextAsync(); var account = JsonConvert.DeserializeObject <JObject>(accountStr); await UserSignedIn.Raise(new Google.User { FamilyName = account["family_name"].Value <string>(), GivenName = account["given_name"].Value <string>(), Email = account["email"].Value <string>(), Name = account["name"].Value <string>(), Id = account["sub"].Value <string>(), Picture = account["picture"].Value <string>(), Token = args.Account.Properties["id_token"] ?? "" }); } }; }
public System.Threading.Tasks.Task <IResponse> GetResponseAsync() { System.Threading.Tasks.TaskCompletionSource <IResponse> tcs = new System.Threading.Tasks.TaskCompletionSource <IResponse>(); tcs.SetResult(new ResponseImpl(xrequest.GetResponseAsync())); return(tcs.Task); }