public static void Authenticate(this KZApplication application, Context context, KZApplication.OnEventHandler onAuthFinish)
        {
            appContext = context;
            if (!application.Initialized)
            {
                application.Initialize().Wait();
            }
            PassiveAuthSettings = new Dictionary <string, string>();

            KidozenApplicationConfig = application.ApplicationConfiguration;

            PassiveAuthSettings.Add("grant_type", "refresh_token");
            PassiveAuthSettings.Add("client_secret", application.applicationKey);
            PassiveAuthSettings.Add("client_id",
                                    Validate(KidozenApplicationConfig, "domain")
                                    );
            PassiveAuthSettings.Add("scope",
                                    Validate(KidozenApplicationConfig.Value <JObject> ("authConfig"), "applicationScope")
                                    );
            PassiveAuthSettings.Add("oauthTokenEndpoint",
                                    Validate(KidozenApplicationConfig.Value <JObject> ("authConfig"), "oauthTokenEndpoint")
                                    );

            var signInUrl = Validate(application.ApplicationConfiguration.Value <JObject> ("authConfig"), "signInUrl");

            var startPassiveAuth = new Intent(appContext, typeof(PassiveAuthActivity));

            startPassiveAuth.AddFlags(ActivityFlags.NewTask);
            startPassiveAuth.PutExtra("signInUrl", signInUrl);
            appContext.StartActivity(startPassiveAuth);
            AuthenticationEventManager.AuthenticationResponseArrived += (object sender, AuthenticationResponseEventArgs e) => {
                Console.WriteLine("*** Success : " + e.Success);
                application.Authenticated = e.Success;
                if (e.Success)
                {
                    application.PassiveAuthenticationInformation = e.TokenInfo;
                }
                else
                {
                    //TODO: display alert
                }
                if (onAuthFinish != null)
                {
                    onAuthFinish.Invoke(application, e);
                }
            };
        }
Example #2
0
        public static void Authenticate(this KZApplication application, KZApplication.OnEventHandler onAuthFinish)
        {
            PassiveAuthSettings = new Dictionary <string, string>();
            if (!application.Initialized)
            {
                application.Initialize().Wait();
            }

            KidozenApplicationConfig = application.ApplicationConfiguration;

            PassiveAuthSettings.Add("grant_type", "refresh_token");
            PassiveAuthSettings.Add("client_secret", application.applicationKey);
            PassiveAuthSettings.Add("client_id", Validate(KidozenApplicationConfig, "domain"));
            PassiveAuthSettings.Add("scope", Validate(KidozenApplicationConfig.Value <JObject> ("authConfig"), "applicationScope"));
            PassiveAuthSettings.Add("oauthTokenEndpoint", Validate(KidozenApplicationConfig.Value <JObject> ("authConfig"), "oauthTokenEndpoint"));

            var signInUrl      = Validate(KidozenApplicationConfig.Value <JObject> ("authConfig"), "signInUrl");
            var authController = new PassiveAuthViewController(signInUrl);
            var wv             = new UINavigationController(authController);

            authController.AuthenticationResponseArrived += (object sender, AuthenticationResponseEventArgs e) => {
                Console.WriteLine("*** Success : " + e.Success);
                application.Authenticated = e.Success;
                if (e.Success)
                {
                    application.PassiveAuthenticationInformation = new Dictionary <string, string>(e.TokenInfo);
                }
                else
                {
                    //TODO: display alert
                }
                if (onAuthFinish != null)
                {
                    onAuthFinish.Invoke(application, e);
                }
            };
            UIApplication.SharedApplication.Delegate.Window.RootViewController.PresentViewController(wv, true,
                                                                                                     new NSAction(() => {
                Console.WriteLine("loading");
            }));

            //OnPassiveAuthentication.Invoke(application, new PassiveAuthenticationEventArgs {Success=e.Success});
        }