Example #1
0
        private void CommandButtonLogin(object obj)
        {
            // Hide any error displayed
            SetErrorMessage(null);

            // Are we aksing the password ?
            if (Model.AskingPassword)
            {
                if (String.IsNullOrEmpty(Model.Password))
                {
                    SetErrorMessage("Invalid password");
                    SetToBusy(false);
                }
                else
                {
                    CurrentApplication.RbApplication.Login(Model.Login, Model.Password, callback =>
                    {
                        if (!callback.Result.Success)
                        {
                            if (callback.Result.HttpStatusCode != 0)
                            {
                                if (callback.Result.IncorrectUseError != null)
                                {
                                    SetErrorMessage(String.Format("{0}: [{1}]", callback.Result.IncorrectUseError.ErrorDetails, callback.Result.IncorrectUseError.ErrorCode));
                                }
                                else
                                {
                                    SetErrorMessage(String.Format("Exception occurs: [{0}]", callback.Result.ExceptionError.Message));
                                }
                            }
                            else
                            {
                                SetErrorMessage("Cannot contact the server. Please check your network settings.");
                            }
                        }
                    });
                }
            }
            // We are not asking password
            else
            {
                // Check email address
                if (IsEmailAddress(Model.Login))
                {
                    SetToBusy(true);

                    // We ask server for SSO URL
                    CurrentApplication.RbApplication.GetAuthenticationSSOUrls(Model.Login, callback =>
                    {
                        if (callback.Result.Success)
                        {
                            List <AuthenticationSSOUrl> urls = callback.Data;

                            // Do we have at least one URL ?
                            if ((urls == null) || (urls?.Count == 0))
                            {
                                Model.AskingPassword = true;
                                SetToBusy(false);
                                return;
                            }

                            // If we have several URLs, the first one different of RAINBOW is taken into account
                            AuthenticationSSOUrl authUrl = urls.FirstOrDefault(x => (x.Type.ToUpper() != "RAINBOW"));

                            // Do we have found one ?
                            if (authUrl == null)
                            {
                                Model.AskingPassword = true;
                                SetToBusy(false);
                                return;
                            }

                            // So we start SSO
                            String uri         = authUrl.LoginUrl;
                            String redirectUri = String.Format("{0}://{1}/", AppConfiguration.URI_SCHEME_FOR_SSO, AppConfiguration.URI_PATH_FOR_SSO); // /!\  This callback must be set on the property "SsoAuthenticationRedirectUrl" on the RB Application used by this SDK
                            StartSSO(uri, redirectUri);
                        }
                        else
                        {
                            SetToBusy(false);

                            if (callback.Result.HttpStatusCode != 0)
                            {
                                if (callback.Result.IncorrectUseError != null)
                                {
                                    SetErrorMessage(String.Format("{0}: [{1}]", callback.Result.IncorrectUseError.ErrorDetails, callback.Result.IncorrectUseError.ErrorCode));
                                }
                                else
                                {
                                    SetErrorMessage(String.Format("Exception occurs: [{0}]", callback.Result.ExceptionError.Message));
                                }
                            }
                            else
                            {
                                SetErrorMessage("Cannot contact the server. Please check your network settings.");
                            }
                        }
                    });
                }
                else
                {
                    SetErrorMessage("Not a valid email address");

                    Model.AskingPassword = false;
                    Model.Connect        = "Continue";
                }
            }
        }
Example #2
0
        private void StepAskingLogin()
        {
            // Check if we want to use SSO
            if ((!ApplicationInfo.USE_SSO) || ApplicationInfo.UseTestEnvironment)
            {
                AskPassword();
                return;
            }

            SetToBusy(true);

            Task task = new Task(() =>
            {
                Helper.SdkWrapper.GetAuthenticationSSOUrls(LoginModel.Login, callback =>
                {
                    if (callback.Result.Success)
                    {
                        List <AuthenticationSSOUrl> urls = callback.Data;

                        // Do we have at least one URL ?
                        if ((urls == null) || (urls?.Count == 0))
                        {
                            AskPassword();
                            return;
                        }

                        // If we have several URLs, the first one different of RAINBOW is taken into account
                        AuthenticationSSOUrl authUrl = urls.FirstOrDefault(x => (x.Type.ToUpper() != "RAINBOW"));

                        // Do we have found one ?
                        if (authUrl == null)
                        {
                            AskPassword();
                            return;
                        }

                        // So we start SSO
                        Uri uri         = new Uri(authUrl.LoginUrl);
                        Uri redirectUri = new Uri("rainbow://callback/"); // /!\  This callback must be set on the property "SsoAuthenticationRedirectUrl" on the RB Application used by this SDK

                        MainThread.BeginInvokeOnMainThread(async() =>
                        {
                            try
                            {
                                var authResult = await WebAuthenticator.AuthenticateAsync(uri, redirectUri);

                                // We take the JWT tkn from Rainbow server (if any)
                                if (authResult.Properties.ContainsKey("tkn"))
                                {
                                    String token = authResult.Properties["tkn"];

                                    // Now start login with this token
                                    Helper.SdkWrapper.LoginWithToken(token, callbackLoginToken =>
                                    {
                                        if (!callbackLoginToken.Result.Success)
                                        {
                                            SetToBusy(false);
                                        }
                                    });
                                }
                                else
                                {
                                    SetToBusy(false);
                                }
                            }
                            catch
                            {
                                // ERROR OCCURS or USER CANCELLED
                                SetToBusy(false);
                            }
                        });
                    }
                    else
                    {
                        SetToBusy(false);
                    }
                });
            });

            task.Start();
        }