Exemplo n.º 1
0
 void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
 {
     Debug.WriteLine(e.Message);
 }
Exemplo n.º 2
0
 private void OnAuthenticationFailed(object sender, AuthenticatorErrorEventArgs e)
 {
     _authenticationDelegate.OnAuthenticationFailed(e.Message, e.Exception);
 }
Exemplo n.º 3
0
 private void auth_Error(object sender, AuthenticatorErrorEventArgs e)
 {
     throw new Xamarin.Auth.AuthException("Auth Error");
 }
        protected void Authentication_Error(object sender, AuthenticatorErrorEventArgs e)
        {
            authenticator_page.Authentication_Error(sender, e);

            return;
        }
Exemplo n.º 5
0
 private void AuthOnError(object sender, AuthenticatorErrorEventArgs authenticatorErrorEventArgs)
 {
     _eventAggregator.GetEvent <LoginFailEvent>().Publish();
 }
Exemplo n.º 6
0
        private async void auth_Failed(object sender, AuthenticatorErrorEventArgs eventArgs)
        {
            await Application.Current.MainPage.DisplayAlert(title : "Login failed!", message : eventArgs.Message, cancel : "Okay");

            canLogin = true;
        }
 private void OnAuthenticationFailed(object sender, AuthenticatorErrorEventArgs e)
 {
 }
		void HandleError (object sender, AuthenticatorErrorEventArgs e)
		{
			var after = keepTryingAfterError ?
				(Action)BeginLoadingInitialUrl :
				(Action)Cancel;

			this.ShowError ("Connection Failed", "Check your Internet connection and try again.", after);
		}
 private void onAuthError(object sender, AuthenticatorErrorEventArgs e)
 {
     DisplayAlert("Google Authentication Error", e.Message, "OK");
 }
Exemplo n.º 10
0
 async void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
 {
     // Gestire eventuali errori nel login.
     Application.Current.Quit();
 }
Exemplo n.º 11
0
 private void AuthOnError(object sender, AuthenticatorErrorEventArgs authenticatorErrorEventArgs)
 {
     OnFail?.Invoke(sender, new OnFailEventArgs {
         Error = authenticatorErrorEventArgs.Message
     });
 }
Exemplo n.º 12
0
 private void ObjOAuth2Authenticator_Error(object sender, AuthenticatorErrorEventArgs e)
 {
     throw new NotImplementedException();
 }
        public async void StartAuthentication(string clientId, string scope, string appSecret, Uri authorizeUrl, Uri redirectUrl, Uri tokenUrl, bool codeChallengeMethod)
        {
            string     codeVerifier = "";
            UriBuilder uriBuilder   = new UriBuilder(authorizeUrl);

            uriBuilder.Query += "?client_id=" + clientId + "&scope=" + Uri.EscapeUriString(scope) + "&response_type=code&redirect_uri=" + Uri.EscapeUriString(redirectUrl.AbsoluteUri);

            // Codice opzionale di sicurezza
            if (codeChallengeMethod)
            {
                codeVerifier = GetCodeVerifier();
                string codeChallenge = Base64URLEncode(EncDecHelper.SHA256Bytes(codeVerifier));
                uriBuilder.Query += "&code_challenge_method=S256&code_challenge=" + codeChallenge;
            }

            try
            {
                // Step 1: richiede il codice di autorizzazione
                WebAuthenticationResult Result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None,
                                                                                                 uriBuilder.Uri,
                                                                                                 redirectUrl);

                if (Result.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    Account account = new Account();

                    // Estraggo il codice
                    string Code        = "";
                    string QueryString = new Uri(Result.ResponseData).Query;
                    QueryString = QueryString.Substring(1); // Salta "?"
                    string[] QueryParams = QueryString.Split('&');
                    for (short i = 0; i < QueryParams.Length; i++)
                    {
                        if (QueryParams[i].Contains("code="))
                        {
                            Code = QueryParams[i].Substring(5);
                            break;
                        }
                    }

                    // Step 2: scambio il codice con un access token
                    HttpClient appClient = new HttpClient();
                    try
                    {
                        List <KeyValuePair <string, string> > Param = new List <KeyValuePair <string, string> >
                        {
                            new KeyValuePair <string, string>("client_id", clientId),
                            new KeyValuePair <string, string>("redirect_uri", Uri.EscapeUriString(redirectUrl.AbsoluteUri)),
                            new KeyValuePair <string, string>("code", Uri.EscapeUriString(Code)),
                            new KeyValuePair <string, string>("scope", scope),
                            new KeyValuePair <string, string>("grant_type", "authorization_code")
                        };

                        // Non è obbligatorio in certi casi (es: Google Drive API per iOS, Android e UWP)
                        if (appSecret != "")
                        {
                            Param.Add(new KeyValuePair <string, string>("client_secret", appSecret));
                        }

                        // Codice opzionale di verifica
                        if (codeChallengeMethod && codeVerifier != "")
                        {
                            Param.Add(new KeyValuePair <string, string>("code_verifier", codeVerifier));
                        }

                        FormUrlEncodedContent Content  = new FormUrlEncodedContent(Param);
                        HttpResponseMessage   Response = await appClient.PostAsync(tokenUrl, Content);

                        if (Response.IsSuccessStatusCode)
                        {
                            // Ottengo un JSON con l'access token, il refesh token e la scadenza.
                            string content = await Response.Content.ReadAsStringAsync();

                            JObject JsonObj = JObject.Parse(content);
                            if (JsonObj != null && JsonObj.ContainsKey("access_token"))
                            {
                                foreach (KeyValuePair <string, JToken> token in JsonObj)
                                {
                                    account.Properties.Add(token.Key, token.Value.ToString());
                                }
                                account.Properties.Add("date_token", DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"));

                                // Step 3: richiedo un nuovo access token e un refresh token per aggiornare il
                                // token (in quando voglio accedere offline alla cartella di OneDrive)
                                OAuthAccountWrapper oAuthAccount = new OAuthAccountWrapper(account);
                                await RefreshToken(oAuthAccount, clientId, redirectUrl, appSecret, tokenUrl);

                                if (oAuthAccount.AccessToken.Length <= 0)
                                {
                                    appClient.Dispose();

                                    Debug.WriteLine("Authetication failed: access token not found in response");
                                    throw new Exception("Access token not found in response");
                                }

                                appClient.Dispose();
                                Debug.WriteLine("Authetication succeeded!");
                            }
                            else
                            {
                                appClient.Dispose();

                                Debug.WriteLine("Authetication failed: malformed response");
                                throw new Exception("Malformed response");
                            }
                        }
                        else
                        {
                            appClient.Dispose();

                            Debug.WriteLine("Authetication failed: " + Response.StatusCode.ToString());
                            throw new Exception("HTTP Error: " + Response.StatusCode + "\nUnable to redeem a token");
                        }

                        AuthenticatorCompletedEventArgs AuthCompletedEventArgs = new AuthenticatorCompletedEventArgs(account);
                        Completed?.Invoke(this, AuthCompletedEventArgs);
                    }
                    catch (Exception Ex)
                    {
                        appClient.Dispose();

                        Debug.WriteLine("Authetication failed: " + Ex.Message);
                        throw;
                    }
                }
                else if (Result.ResponseStatus != WebAuthenticationStatus.UserCancel)
                {
                    Debug.WriteLine("Authetication failed: " + Result.ResponseStatus.ToString());
                    throw new Exception("HTTP Error code: " + Result.ResponseErrorDetail + "\nError: " + Result.ResponseData);
                }
                else
                {
                    Debug.WriteLine("Authetication cancelled by user");

                    // Passando null si avrà IsAuthenticated a false.
                    // Vedi https://github.com/xamarin/Xamarin.Auth/blob/master/source/Core/Xamarin.Auth.Common.LinkSource/AuthenticatorCompletedEventArgs.cs
                    AuthenticatorCompletedEventArgs AuthCompletedEventArgs = new AuthenticatorCompletedEventArgs(null);
                    Completed?.Invoke(this, AuthCompletedEventArgs);
                }
            }
            catch (Exception Ex)
            {
                Debug.WriteLine("Authetication failed: " + Ex.Message);

                AuthenticatorErrorEventArgs AuthCompletedEventArgs = new AuthenticatorErrorEventArgs(Ex);
                Error?.Invoke(this, AuthCompletedEventArgs);
            }
        }
Exemplo n.º 14
0
 private void OnOAuth2Error(object sender, AuthenticatorErrorEventArgs e)
 {
     Error?.Invoke(sender, e);
 }
 private void OnTwitterAuthenticationFailed(object sender, AuthenticatorErrorEventArgs e)
 {
     DisplayAlert("Twitter Login Failed", "", "Close");
 }
        private async void Authenticator_Error(object sender, AuthenticatorErrorEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("AuthenticatorPageRenderer: In UWP Authenticator_Error");

            return;
        }
Exemplo n.º 17
0
 private void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
 {
     MessageBox.Show(e.Message, "Error", MessageBoxButton.OK);
     //NavigationService.GoBack();
 }
		void HandleError (object sender, AuthenticatorErrorEventArgs e)
		{
			var after = keepTryingAfterError ?
				(Action)BeginLoadingInitialUrl :
				(Action)Cancel;

			if (authenticator.ShowUIErrors) {
				if (e.Exception != null) {
					this.ShowError ("Authentication Error", e.Exception, after);
				} else {
					this.ShowError ("Authentication Error", e.Message, after);
				}
			} else {
				after ();
			}			
		}
Exemplo n.º 19
0
 private void AuthOnError(object sender, AuthenticatorErrorEventArgs e)
 {
 }