Ejemplo n.º 1
0
        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);
                    }
                });
            });
        }
Ejemplo n.º 2
0
        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"] ?? ""
                    });
                }
            };
        }
Ejemplo n.º 3
0
 public OAuth2RequestImpl(Xamarin.Auth.OAuth2Request xrequest)
 {
     this.xrequest = xrequest;
 }
Ejemplo n.º 4
0
 public IOAuth2Request OAuth2Request(string method, Uri url, Dictionary<string, string> parameters, Account account)
 {
     Xamarin.Auth.OAuth2Request xrequest = new Xamarin.Auth.OAuth2Request(method, url, parameters, (Xamarin.Auth.Account)account.xAccount);
     return new OAuth2RequestImpl(xrequest);
 }
Ejemplo n.º 5
0
 public OAuth2RequestImpl(Xamarin.Auth.OAuth2Request xrequest)
 {
     this.xrequest = xrequest;
 }
Ejemplo n.º 6
0
 public IOAuth2Request OAuth2Request(string method, Uri url, Dictionary <string, string> parameters, Account account)
 {
     Xamarin.Auth.OAuth2Request xrequest = new Xamarin.Auth.OAuth2Request(method, url, parameters, (Xamarin.Auth.Account)account.xAccount);
     return(new OAuth2RequestImpl(xrequest));
 }