예제 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Initialize our native providers
            SimpleAuth.Providers.Google.Init(this.Application);
            SimpleAuth.Providers.Facebook.Init(this.Application, false);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            FindViewById<Button>(Resource.Id.loginGoogleNative).Click += async (sender, e) =>
            {
                // Create an OAuth credential and use its clientId
                var clientId = "28116949007-uho7tcbsm17l8uq7t96fk8i9d6ftugnd"; // Provide with or without the '.apps.googleusercontent.com' suffix

                var google = new SimpleAuth.Providers.GoogleApi("google", clientId, "native") {
                    Scopes = new [] { "https://www.googleapis.com/auth/userinfo.profile" }
                };

                var account = await AuthAsync(google);

                // .. Do something with account
            };

            FindViewById<Button>(Resource.Id.loginFacebookNative).Click += async (sender, e) =>
            {
                // Use the App ID
                var clientId = "1475840585777919";

                var fb = new SimpleAuth.Providers.FacebookApi("facebook", clientId, "native");

                var account = await AuthAsync(fb);

                // .. Do something with account
            };

            FindViewById<Button>(Resource.Id.loginGeneric).Click += async (sender, e) =>
            {
                var oauth = new OAuthApi("someprovider", new OAuthAuthenticator(
                    "authUrl",
                    "tokenUrl",
                    "redirecturl",
                    "clientid",
                    "clientsecret"));
                    
                var account = await AuthAsync(oauth);

                // .. Do something with account
            };
        }
예제 #2
0
        async Task<Account> AuthAsync(OAuthApi api)
        {
            Account result = null;
            try
            {
				result = await api.Authenticate();
				Toast.MakeText(this, "Successfully Authenticated!", ToastLength.Long).Show();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Toast.MakeText(this, "Authentication Faild!", ToastLength.Long).Show();
            }

            if (result != null)
                Console.WriteLine(await result.ToJsonAsync());

            return result;
        }
예제 #3
0
        public App()
        {
            var scopes = new[]
            {
                "https://www.googleapis.com/auth/userinfo.email",
                "https://www.googleapis.com/auth/userinfo.profile"
            };
            api = new GoogleApi("google",
                   "clientid",
                "clientsecret",new ModernHttpClient.NativeMessageHandler())
            {
                Scopes = scopes,
            };

            var button = new Button
            {
                Text = "Login",
            };
            button.Clicked += async (sender, args) =>
            {
                try
                {
                    var account = await api.Authenticate();

                    Console.WriteLine(account.Identifier);
                }
                catch (TaskCanceledException ex)
                {
                    Console.WriteLine("Canceled");
                }
            };
            // The root page of your application
            MainPage = new ContentPage {
                Content = new StackLayout {
                    VerticalOptions = LayoutOptions.Center,
                    Children = {
                        button
                    }
                }
            };
        }
예제 #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            api = new OAuthApi("google",new OAuthAuthenticator(
                "authUrl",
                "tokenUrl",
                "redirecturl",
                "clientid",
                "clientsecret"));
            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            button.Text = "Login";
            button.Click += async delegate
            {
                var account = await api.Authenticate();
                Console.WriteLine(account.Identifier);
            };
        }