Example #1
0
        public async Task StartSignInAsync()
        {
            AuthData authData = null;

            var domain   = Settings.AuthDomain;
            var clientId = Settings.AuthClientId;
            var audience = Settings.AuthAudience;
            var activity = CrossCurrentActivity.Current.Activity;

            _authClient = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = domain,
                ClientId = clientId,
                Activity = activity
            });

            try
            {
                _authState = await _authClient.PrepareLoginAsync(new { audience = audience });

                var uri    = Android.Net.Uri.Parse(_authState.StartUrl);
                var intent = new Intent(Intent.ActionView, uri);
                intent.AddFlags(ActivityFlags.NoHistory);
                activity.StartActivity(intent);
            }
            catch (Exception ex)
            {
                authData = new AuthData("Login error!", false, null, null, string.Format("Error occured: {0}", ex.Message));
            }

            AuthData = authData;
        }
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            //LoginScreenControl<CredentialsProvider, LoginScreenMessages>.Activate(this);
            //var auth = new OAuth2Authenticator(
            //                clientId: "291353537939776",
            //                scope: "",
            //                authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
            //                redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html"));
            //auth.Completed += (sender, eventArgs) =>
            //{

            //};

            //var client = new Auth0Client(new Auth0ClientOptions


            client = new Auth0Client(new Auth0ClientOptions
            {
                Domain       = "germakuber.auth0.com",
                ClientId     = "cFLRdKP28o2DHVB8Ea0iRfg6A74BwvOv",
                Activity     = this,
                ClientSecret = "m31h6Jr8SZ6AyIBsck6zUS6Md5Fj6zIuA69KNHcYXmkeXjRX-Ps8JykoNTt-ZdHC"
            });
            // StartActivity(auth.GetUI(this));
            authorizeState = await client.PrepareLoginAsync();

            var uri    = Android.Net.Uri.Parse(authorizeState.StartUrl);
            var intent = new Intent(Intent.ActionView, uri);

            intent.AddFlags(ActivityFlags.NoHistory);
            StartActivity(intent);
        }
Example #3
0
        private async void LoginButton_TouchUpInside(object sender, EventArgs e)
        {
            var client = new Auth0Client(new Auth0ClientOptions
            {
                Domain     = "ash123.auth0.com",
                ClientId   = "nwJxiC7ILZnVMabtAaGif9MNTagMpwXM",
                Controller = this
            });

            var loginResult = await client.LoginAsync();

            var sb = new StringBuilder();

            if (loginResult.IsError)
            {
                sb.AppendLine("An error occurred during login:"******"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();
        }
        private async void LoginButton_Click(object sender, EventArgs e)
        {
            string domain   = ConfigurationManager.AppSettings["Auth0:Domain"];
            string clientId = ConfigurationManager.AppSettings["Auth0:ClientId"];

            client = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = domain,
                ClientId = clientId
            });

            var extraParameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(connectionNameComboBox.Text))
            {
                extraParameters.Add("connection", connectionNameComboBox.Text);
            }

            if (!string.IsNullOrEmpty(audienceTextBox.Text))
            {
                extraParameters.Add("audience", audienceTextBox.Text);
            }

            DisplayResult(await client.LoginAsync(extraParameters: extraParameters));
        }
Example #5
0
        private async void OnLogin(object sender, EventArgs e)
        {
            var domain   = ConfigurationManager.AppSettings["auth0.domain"].ToSecureString();
            var client   = ConfigurationManager.AppSettings["auth0.client.id"].ToSecureString();
            var audience = ConfigurationManager.AppSettings["auth0.audience"].ToSecureString();

            var options = new Auth0ClientOptions
            {
                Domain   = domain.ToUnsecureString(),
                ClientId = client.ToUnsecureString()
            };

            var auth0 = new Auth0Client(options);

            options.PostLogoutRedirectUri = options.RedirectUri;

            var param = new Dictionary <string, string>()
            {
                { "audience", audience.ToUnsecureString() }
            };

            Hide();

            var login = await auth0.LoginAsync(param);

            if (login.IsError)
            {
                Show();
            }
        }
Example #6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            //Redirect = new Misc(bundle);//FIXME: label_1: this causes execution fail in device



            SetContentView(Resource.Layout.Main);

            //Xamarin.Forms.Forms.Init(this, bundle);//label_1


            loginButton        = FindViewById <Button>(Resource.Id.LoginButton);
            loginButton.Click += LoginButtonOnClick;

            userDetailsTextView = FindViewById <TextView>(Resource.Id.UserDetailsTextView);
            userDetailsTextView.MovementMethod = new ScrollingMovementMethod();
            userDetailsTextView.Text           = String.Empty;

            client = new Auth0Client(new Auth0ClientOptions
            {
                //Domain = Resources.GetString(Resource.Strings.auth0_domain),
                Domain = "athelog.auth0.com",
                //ClientId = Resources.GetString(Resources.String.auth0_client_id),
                ClientId = "i9urWnrS5aYbFfB5SuaGi6X0aNI1pbSA",
                Activity = this
            });
        }
Example #7
0
        public async Task <UserLogin> Login(string username, string password)
        {
            UserLogin user = null;
            var       externalLoginConfigurationService = DependencyService.Get <IExternalLoginConfigurationService>();

            try
            {
                var auth0 = new Auth0Client(externalLoginConfigurationService.Auth0Domain,
                                            externalLoginConfigurationService.Auth0ClientId);

                if (auth0 != null)
                {
                    var aDFSUser = await auth0.LoginAsync(externalLoginConfigurationService.Auth0ConnectionName, username, password);

                    if (aDFSUser != null)
                    {
                        Console.WriteLine("Logged in as " + aDFSUser.Profile["name"]);
                    }
                }

                return(user);
            }
            catch (TaskCanceledException ex)
            {
                var navigationService = DependencyService.Get <INavigationService>();
                await navigationService.PopAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            var client = new Auth0Client(new Auth0ClientOptions
            {
                Domain      = "jerrie.auth0.com",
                ClientId    = "vV9twaySQzfGesS9Qs6gOgqDsYDdgoKE",
                Scope       = "openid profile offline_access",
                Browser     = new SystemWebBrowser(),
                RedirectUri = "http://127.0.0.1:7890/"
            });

            var loginResult = await client.LoginAsync();

            if (loginResult.IsError)
            {
                Debug.WriteLine($"An error occurred during login: {loginResult.Error}");
            }
            else
            {
                Debug.WriteLine($"id_token: {loginResult.IdentityToken}");
                Debug.WriteLine($"access_token: {loginResult.AccessToken}");
                Debug.WriteLine($"refresh_token: {loginResult.RefreshToken}");

                Debug.WriteLine($"name: {loginResult.User.FindFirst(c => c.Type == "name")?.Value}");
                Debug.WriteLine($"email: {loginResult.User.FindFirst(c => c.Type == "email")?.Value}");

                foreach (var claim in loginResult.User.Claims)
                {
                    Debug.WriteLine($"{claim.Type} = {claim.Value}");
                }
            }
        }
Example #9
0
        private async void button1_Click(object sender, EventArgs e)
        {
            var client = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = "jerrie.auth0.com",
                ClientId = "vV9twaySQzfGesS9Qs6gOgqDsYDdgoKE"
            });

            var loginResult = await client.LoginAsync();

            if (loginResult.IsError)
            {
                Debug.WriteLine($"An error occurred during login: {loginResult.Error}");
            }
            else
            {
                Debug.WriteLine($"id_token: {loginResult.IdentityToken}");
                Debug.WriteLine($"access_token: {loginResult.AccessToken}");
                Debug.WriteLine($"refresh_token: {loginResult.RefreshToken}");

                Debug.WriteLine($"name: {loginResult.User.FindFirst(c => c.Type == "name")?.Value}");
                Debug.WriteLine($"email: {loginResult.User.FindFirst(c => c.Type == "email")?.Value}");

                foreach (var claim in loginResult.User.Claims)
                {
                    Debug.WriteLine($"{claim.Type} = {claim.Value}");
                }
            }
        }
        private async void LoginButton_TouchUpInside(object sender, EventArgs e)
        {
            _client = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = "{DOMAIN}",
                ClientId = "{CLIENT_ID}",
                Scope    = "openid profile"
            });

            var loginResult = await _client.LoginAsync();

            var sb = new StringBuilder();

            if (loginResult.IsError)
            {
                sb.AppendLine("An error occurred during login:"******"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();
        }
        public async Task <LoginResult> AuthenticateAsync()
        {
            string domain     = ConfigurationManager.AppSettings["Auth0:Domain"];
            string clientId   = ConfigurationManager.AppSettings["Auth0:ClientId"];
            string audience   = ConfigurationManager.AppSettings["Auth0:Audience"];
            string connection = ConfigurationManager.AppSettings["Auth0:Connection"];
            string scope      = ConfigurationManager.AppSettings["Auth0:Scope"];

            _client = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = domain,
                ClientId = clientId,
                Browser  = new EdgeWebView("Tanka Chat for WPF sample", 600, 810),
                Scope    = scope
            });

            var extraParameters = new Dictionary <string, string>()
            {
                { "connection", connection },
                { "audience", audience }
            };
            var loginResult = await _client.LoginAsync(extraParameters : extraParameters);

            if (loginResult.IsError)
            {
                // Handle errors on the caller.
                Debug.WriteLine(loginResult.Error);
            }

            return(loginResult);
        }
        private async void LoginButton_OnClick(object sender, RoutedEventArgs e)
        {
            string domain   = ConfigurationManager.AppSettings["Auth0:Domain"];
            string clientId = ConfigurationManager.AppSettings["Auth0:ClientId"];

            var client = new Auth0Client(new Auth0ClientOptions
            {
                Domain      = domain,
                ClientId    = clientId,
                Browser     = new SystemWebBrowser(),
                RedirectUri = "http://127.0.0.1:7890/"
            });

            var extraParameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(connectionNameComboBox.Text))
            {
                extraParameters.Add("connection", connectionNameComboBox.Text);
            }

            if (!string.IsNullOrEmpty(audienceTextBox.Text))
            {
                extraParameters.Add("audience", audienceTextBox.Text);
            }

            DisplayResult(await client.LoginAsync(extraParameters: extraParameters));
        }
Example #13
0
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            string domain   = "{DOMAIN}";
            string clientId = "{CLIENT_ID}";

            client = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = domain,
                ClientId = clientId
            });

            var extraParameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(connectionNameAutoSuggestBox.Text))
            {
                extraParameters.Add("connection", connectionNameAutoSuggestBox.Text);
            }

            if (!string.IsNullOrEmpty(audienceTextBox.Text))
            {
                extraParameters.Add("audience", audienceTextBox.Text);
            }

            DisplayResult(await client.LoginAsync(extraParameters: extraParameters));
        }
Example #14
0
        public async Task <bool> Authenticate()
        {
            var cached = _tokenCache.GetUser();

            if (cached == null)
            {
                var authClient = new Auth0Client(Domain, ClientId);
                var result     =
                    await
                    authClient.LoginAsync()
                    .ContinueWith(t => t.Result, TaskScheduler.FromCurrentSynchronizationContext());

                if (result == null)
                {
                    return(false);
                }

                AuthenticatedUser = result;
                _tokenCache.StoreUser(result);
            }
            else
            {
                AuthenticatedUser = cached;
            }

            return(true);
        }
Example #15
0
        private async void LoginButton_TouchUpInside(object sender, EventArgs e)
        {
            _client = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = "jerrie.auth0.com",
                ClientId = "vV9twaySQzfGesS9Qs6gOgqDsYDdgoKE"
            });

            var loginResult = await _client.LoginAsync(null);

            var sb = new StringBuilder();

            if (loginResult.IsError)
            {
                sb.AppendLine("An error occurred during login:"******"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();
        }
Example #16
0
        public async Task StartSignInAsync()
        {
            AuthData authData = null;

            var domain   = Settings.AuthDomain;
            var clientId = Settings.AuthClientId;
            var audience = Settings.AuthAudience;
            var client   = new Auth0Client(new Auth0ClientOptions {
                Domain = domain, ClientId = clientId
            });

            try
            {
                var result = await client.LoginAsync(new { audience = audience });

                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;
        }
        public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            if (_cancelledByUser || _justLoggedIn)
            {
                return;
            }
            Auth0Client auth0Client = null;

            //IdentityService identityService = null;
            if (_nativeView == null)
            {
                return;
            }
            var message = String.Empty;

            try
            {
                auth0Client = new Auth0Client(App.Instance.OAuthSettings.Domain, App.Instance.OAuthSettings.ClientId);                        //SimpleIoc.Default.GetInstance<Auth0Client>();
                //identityService = SimpleIoc.Default.GetInstance<IIdentityService>() as IdentityService;
                //if (identityService == null) return;
                var user = await auth0Client.LoginAsync(ViewController, "servcorp.adfs.prod", true);


                _justLoggedIn = true;


                //					if (eventArgs.IsAuthenticated) {
                //						// Use eventArgs.Account to do wonderful things
                App.Instance.SaveToken(user.Auth0AccessToken);

                App.Instance.SuccessfulLoginAction.Invoke();
                //					} else {
                //						// The user cancelled
                //					}
            }
            catch (System.Threading.Tasks.TaskCanceledException cancelException)
            {
                App.Instance.FailureLoginAction.Invoke();
                //await App.Instance.NavigationPage.Navigation.PushModalAsync (new StartPage());
                MessagingCenter.Send <App> (App.Instance, "AuthenticationFailed");

                if (cancelException.Task != null &&
                    cancelException.Task.Status == TaskStatus.Canceled)
                {
                    _cancelledByUser = true;
                }
                message = cancelException.Message;
                App.Instance.ErrorMessage = message;
                App.Instance.NavigationPage.PopToRootAsync().Wait();
            }
            catch (Exception exception)
            {
                message = exception.Message;
                //throw;
            }

            //if (identityService != null) identityService.SetIdentity(auth0Client, _cancelledByUser, message);
        }
Example #18
0
 public AuthenticationService()
 {
     _auth0Client = new Auth0Client(new Auth0ClientOptions
     {
         Domain   = "",
         ClientId = ""
     });
 }
        private async void Login()
        {
            var auth0 = new Auth0Client(
                "majji.auth0.com",
                "sfBNUQUSidqrlTxSeQphLjZ2SJ8J49VI");

            var user = await auth0.LoginAsync();
        }
Example #20
0
 public AuthenticationService()
 {
     _auth0Client = new Auth0Client(new Auth0ClientOptions
     {
         Domain   = Credentials.Domain,
         ClientId = Credentials.ClientId,
     });
 }
 public AuthenticationService()
 {
     _auth0Client = new Auth0Client(new Auth0ClientOptions
     {
         Domain   = AuthenticationConfig.Domain,
         ClientId = AuthenticationConfig.ClientId
     });
 }
        public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            try
            {
                var loginAuth0PageRenderService = DependencyService.Get <ILoginAuth0PageRenderService>();

                await loginAuth0PageRenderService.LoginWrapper(async() =>
                {
                    var externalLoginConfigurationService = DependencyService.Get <IExternalLoginConfigurationService>();
                    if (externalLoginConfigurationService == null)
                    {
                        throw new ArgumentNullException(nameof(externalLoginConfigurationService));
                    }


                    var auth0 = new Auth0Client(externalLoginConfigurationService.Auth0Domain,
                                                externalLoginConfigurationService.Auth0ClientId);

                    var user = await auth0.LoginAsync(ViewController, externalLoginConfigurationService.Auth0ConnectionName,
                                                      false);
                    if (user != null)
                    {
                        Console.WriteLine("Logged in as " + user.Profile["name"]);
                        try
                        {
                            var userLogin = new UserLogin
                            {
                                UserProfile = new UserProfile
                                {
                                    DisplayName = user.Profile.GetKeyValue("name"),
                                    Image       = user.Profile.GetKeyValue("picture_large"),
                                    Email       = user.Profile.GetKeyValue("email"),
                                    Facebook    = user.Profile.GetKeyValue("link"),
                                    FirstName   = user.Profile.GetKeyValue("given_name"),
                                    LastName    = user.Profile.GetKeyValue("family_name")
                                },
                                Auth0AccessToken = user.Auth0AccessToken,
                                RefreshToken     = user.RefreshToken,
                                IdToken          = user.IdToken,
                                DateLogin        = DateTime.Now
                            };
                            return(userLogin);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }
                    }
                    return(null);
                });
            }
            catch (Exception e)
            {
            }
        }
 public async Task LogOut_User()
 {
     Auth0Client _client = new Auth0Client(new Auth0ClientOptions
     {
         Domain   = "transfyr.auth0.com",
         ClientId = "PgIXHiooFM0RQLzr2HS0o4khcJovGvkI",
     });
     await _client.LogoutAsync();
 }
Example #24
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            loginButton.Click += loginButton_Click;
            Client             = new Auth0Client(PortalId);

            ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/AuthenticationServices/Auth0/authprovider.css");
        }
Example #25
0
        public SettingsViewController(IntPtr handle) : base(handle)
        {
            _settingsService = ServiceLocator.Current.GetInstance <ISettingsService>();

            _auth0 = new Auth0Client(
                _settingsService.Auth0Domain,
                _settingsService.Auth0ClientId
                );
        }
Example #26
0
 public Auth0CodeClient(IApplicationSettingsRepository settings)
 {
     if (settings == null)
     {
         throw new ArgumentNullException(nameof(settings));
     }
     _settings = settings;
     _client   = new Auth0Client(_settings.GetStringValue("auth0:domain"), _settings.GetStringValue("auth0:clientid"));
 }
Example #27
0
 public AuthClient()
 {
     _auth0Client = new Auth0Client(new Auth0ClientOptions
     {
         Domain   = Constants.DOMAIN,
         ClientId = Constants.ANDROID_CLIENT_ID,
         Scope    = "openid offline_access"
     });
 }
Example #28
0
        public MainPage()
        {
            this.InitializeComponent();

            _auth0Client = new Auth0Client(new Auth0ClientOptions
            {
                Domain   = "jerrie.auth0.com",
                ClientId = "vV9twaySQzfGesS9Qs6gOgqDsYDdgoKE"
            });
        }
Example #29
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            var auth0 = new Auth0Client(
                "mdocs.auth0.com",
                "kgKQd16fCm2ZH5w5UeiRHvUY0O2Z0gbK",
                "rEwJ0hKCocy4fk7OXdrsuQJRQwiBPLqqMBONiwnIWN2BFnuztthdeGsPeXc2Bh8X");

            auth0.LoginAsync(null)
            .ContinueWith(Authenticated, TaskScheduler.FromCurrentSynchronizationContext());
        }
 public AuthenticationService()
 {
     _auth0Client = new Auth0Client(new Auth0ClientOptions
     {
         Domain      = AppSettings.Configuration.Auth.Domain,
         ClientId    = AppSettings.Configuration.Auth.ClientId,
         Scope       = "openid email profile offline_access",
         LoadProfile = true
     });
 }