Beispiel #1
0
        public async Task AfterSignInAsync(params object[] args)
        {
            AuthData authData = null;

            try
            {
                var intent = args[0] as Intent;
                var result = await _authClient.ProcessResponseAsync(intent.DataString, _authState);

                if (result.IsError)
                {
                    authData = new AuthData("Login error!", false, null, null, string.Format("Error occured: {0}", result.Error));
                }
                else
                {
                    authData = new AuthData(GetAuthUsername(result.User), true, result.AccessToken, result.AccessTokenExpiration, null);
                }
            }
            catch (Exception ex)
            {
                authData = new AuthData("Login error!", false, null, null, string.Format("Error occured: {0}", ex.Message));
            }

            AuthData = authData;

            if (AuthData.IsAuthenticated)
            {
                ViewManager.ChangeView(ViewType.Ready);
            }
            else
            {
                await _dialog.AlertAsync("Alert", AuthData.Error);
            }
        }
Beispiel #2
0
        protected override async void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);

            var loginResult = await client.ProcessResponseAsync(intent.DataString, authorizeState);

            var sb = new StringBuilder();

            if (loginResult.IsError)
            {
                sb.AppendLine($"An error occurred during login: {loginResult.Error}");
            }
            else
            {
                //debug info
                sb.AppendLine("Welcome user");
                //sb.AppendLine($"ID Token: {loginResult.IdentityToken}");
                //sb.AppendLine($"Access Token: {loginResult.AccessToken}");
                //sb.AppendLine($"Refresh Token: {loginResult.RefreshToken}");

                sb.AppendLine();

                sb.AppendLine("-- Claims --");
                foreach (var claim in loginResult.User.Claims)
                {
                    sb.AppendLine($"{claim.Type} = {claim.Value}");
                }

                //redirect
                RedirectToActions();
            }

            userDetailsTextView.Text = sb.ToString();
        }
Beispiel #3
0
        protected override async void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);

            var loginResult = await client.ProcessResponseAsync(intent.DataString, authorizeState);

            var sb = new StringBuilder();

            if (loginResult.IsError)
            {
                sb.AppendLine($"An error occurred during login: {loginResult.Error}");

                LoginManager.Instance.IsAuthenticated = false;
            }
            else
            {
                LoginManager.Instance.IsAuthenticated = true;
                //sb.AppendLine($"ID Token: {loginResult.IdentityToken}");
                //sb.AppendLine($"Access Token: {loginResult.AccessToken}");
                //sb.AppendLine($"Refresh Token: {loginResult.RefreshToken}");

                //sb.AppendLine();

                //sb.AppendLine("-- Claims --");
                //foreach (var claim in loginResult.User.Claims)
                //{
                //    sb.AppendLine($"{claim.Type} = {claim.Value}");
                //}
            }
        }
 protected override async void OnNewIntent(Intent intent)
 {
     base.OnNewIntent(intent);
     try
     {
         var loginResult = await client.ProcessResponseAsync(intent.DataString, authorizeState);
     }
     catch (Exception ex)
     {
     }
 }
        protected override async void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);

            var loginResult = await client.ProcessResponseAsync(intent.DataString, authorizeState);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.SetMessage("ID Token: " + loginResult.IdentityToken.Substring(0, 10));
            builder.SetTitle("Sign-in result");
            builder.Create().Show();

            isAuthenticated = !loginResult.IsError;
            currentUser     = loginResult.User.FindFirst("sub").Value;

            OnAuthentication(EventArgs.Empty);
        }
Beispiel #6
0
        protected override async void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);

            var loginResult = await _client.ProcessResponseAsync(intent.DataString, authorizeState);

            var sb = new StringBuilder();

            if (loginResult.IsError)
            {
                sb.AppendLine($"An error occurred during login: {loginResult.Error}");
            }
            else
            {
                sb.AppendLine($"ID Token: {loginResult.IdentityToken}");
                sb.AppendLine($"Access Token: {loginResult.AccessToken}");
                sb.AppendLine($"Refresh Token: {loginResult.RefreshToken}");

                sb.AppendLine();

                sb.AppendLine("-- Claims --");
                foreach (var claim in loginResult.User.Claims)
                {
                    sb.AppendLine($"{claim.Type} = {claim.Value}");
                }
            }

            _userDetailsTextView.Text = sb.ToString();

            /*
             * // If we are receiving an intent and we are busy authenticating, then we need to close the authentication
             * // loop by Send-ing the data string of the intent with the ActivityMediator.
             * // The internal process is that the DataString will contain a code which the Auth0 OIDC client will exchange
             * // for the tokens. It will also complete the task which was await-ed when you called LoginAsync() so your code
             * // will resume from that point on
             * if (_authenticating)
             * {
             *  _authenticating = false;
             *  ActivityMediator.Instance.Send(intent.DataString);
             * }
             */
        }
Beispiel #7
0
        protected override void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);
            //var loginInfo = await client.ProcessResponseAsync(intent.DataString, authState);
            var task = Task.Run(async() => await client.ProcessResponseAsync(intent.DataString, authState));

            task.Wait();
            var loginInfo = task.Result;

            if (loginInfo.IsError)
            {
                ToastMessage msg = new ToastMessage();
                msg.LongAlert("Error logging in: " + loginInfo.Error);
            }
            else
            {
                AppSettings.Auth0Details.init();
                AppSettings.Auth0Details.identity  = loginInfo.User.FindFirst("sub")?.Value;
                AppSettings.Auth0Details.logged_in = true;
            }
        }
        protected override async void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);

            var loginResult = await client.ProcessResponseAsync(intent.DataString, authorizeState);

            var sb = new StringBuilder();

            if (loginResult.IsError)
            {
                sb.AppendLine($"An error occurred during login: {loginResult.Error}");
            }
            else
            {
                sb.AppendLine($"ID Token: {loginResult.IdentityToken}");
                sb.AppendLine($"Access Token: {loginResult.AccessToken}");
                sb.AppendLine($"Refresh Token: {loginResult.RefreshToken}");
                sb.AppendLine();

                sb.AppendLine("-- Claims --");
                foreach (var claim in loginResult.User.Claims)
                {
                    if (claim.Type == "nickname")
                    {
                        // Save username and token
                        SaveCredentials(claim.Value, loginResult.AccessToken);
                    }
                    sb.AppendLine($"{claim.Type} = {claim.Value}");
                }

                StartActivity(typeof(XamarinForm));
                Finish();
            }

            //userDetailsTextView.Text = sb.ToString();
        }