public Auth() { #endif new AccountStoreImpl(); // invoke static constructor auth1 = new OAuth1AuthenticatorImpl(); auth2 = new OAuth2AuthenticatorImpl(); }
public LimiLabsAdapter(IMailboxLabels mailboxLabels, IOAuth2Authenticator oAuth2Authenticator) { Check.If(mailboxLabels).IsNotNull(); Check.If(oAuth2Authenticator).IsNotNull(); _mailboxLabels = mailboxLabels; _oAuth2Authenticator = oAuth2Authenticator; }
void Authenticate(IOAuth2Authenticator auth, AuthProvider ap, List<Account> accounts) { if (accounts.Count == 0) { auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { try { AccountStore.Create().Save(eventArgs.Account, ap.name); PerformAuth2TestRequests(ap, eventArgs.Account); } catch (Exception ex) { ErrorText = ex.Message; } } else { ErrorText = "Authenticate: Not Authenticated"; return; } }; auth.Error += (sender, eventArgs) => { ErrorText += "Authenticate: Error:" + eventArgs.Message + "\n"; Exception ex = eventArgs.Exception; for (Exception inner = eventArgs.Exception; inner != null; inner = inner.InnerException) { ErrorText += "Message:" + inner.Message + "\n"; } return; }; try { if (ap.ForceRequestTypeOfCode) { auth.OAuth2Authenticator(ap.clientId, ap.scope, new Uri(ap.authorizeUrl), new Uri(ap.redirectUrl), "{0}?client_id={1}&redirect_uri={2}&response_type=code&scope={4}&state={5}"); } else { auth.OAuth2Authenticator(ap.clientId, ap.scope, new Uri(ap.authorizeUrl), new Uri(ap.redirectUrl)); } } catch (Exception ex) { ErrorText = "Authenticate: Exception:"; for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException) { ErrorText += "Message:" + inner.Message + "\n"; } foreach (KeyValuePair<string, string> p in accounts[0].Properties) ErrorText += "Key:" + p.Key + " Value:" + p.Value + "\n"; } } else PerformAuth2TestRequests(ap, accounts[0]); // TODO: implement error handling. If error is caused by expired token, renew token. }
private void Setup(IOAuth2Authenticator authenticator, Environment environment) { _OAuth2Authenticator = authenticator; Environment = environment; InitializeAPIs(); }
public EbayClient(IOAuth2Authenticator authenticator, Environment environment = Environment.Production) { Setup(authenticator, environment); }
void Authenticate(IOAuth2Authenticator auth, AuthProvider ap, List <Account> accounts) { if (accounts.Count == 0) { auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { try { AccountStore.Create().Save(eventArgs.Account, ap.name); PerformAuth2TestRequests(ap, eventArgs.Account); } catch (Exception ex) { ErrorText = ex.Message; } } else { ErrorText = "Authenticate: Not Authenticated"; return; } }; auth.Error += (sender, eventArgs) => { ErrorText += "Authenticate: Error:" + eventArgs.Message + "\n"; Exception ex = eventArgs.Exception; for (Exception inner = eventArgs.Exception; inner != null; inner = inner.InnerException) { ErrorText += "Message:" + inner.Message + "\n"; } return; }; try { if (ap.ForceRequestTypeOfCode) { auth.OAuth2Authenticator(ap.clientId, ap.scope, new Uri(ap.authorizeUrl), new Uri(ap.redirectUrl), "{0}?client_id={1}&redirect_uri={2}&response_type=code&scope={4}&state={5}"); } else { auth.OAuth2Authenticator(ap.clientId, ap.scope, new Uri(ap.authorizeUrl), new Uri(ap.redirectUrl)); } } catch (Exception ex) { ErrorText = "Authenticate: Exception:"; for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException) { ErrorText += "Message:" + inner.Message + "\n"; } foreach (KeyValuePair <string, string> p in accounts[0].Properties) { ErrorText += "Key:" + p.Key + " Value:" + p.Value + "\n"; } } } else { PerformAuth2TestRequests(ap, accounts[0]); // TODO: implement error handling. If error is caused by expired token, renew token. } }
/// <summary> /// Handles the logic of the authentication with the OAuth2 Authentication provider /// </summary> /// <param name="auth">The authenticater</param> /// <param name="accounts">List of registered accounts for the choosen Service</param> void Authenticate(IOAuth2Authenticator auth, List<Account> accounts) { // Checks if there any accounts stored. // if (accounts.Count == 0) // { // EventHandler: When an auth is completed this will be executed. auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { try { AccountStore.Create().Save(eventArgs.Account, AuthProvider.Name); PerformAuth2TestRequests(eventArgs.Account); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } else { System.Diagnostics.Debug.WriteLine("Authenticate: Not Authenticated"); return; } }; auth.Error += (sender, eventArgs) => { System.Diagnostics.Debug.WriteLine("Authenticate: Error:" + eventArgs.Message); Exception ex = eventArgs.Exception; for (Exception inner = eventArgs.Exception; inner != null; inner = inner.InnerException) { System.Diagnostics.Debug.WriteLine("Message:" + inner.Message); } return; }; try { // This is were the user will meet the OAuth2 providers interface // When the auth is complete the EventHandler under the IF-statement will be run. auth.OAuth2Authenticator(AuthProvider.ClientId, AuthProvider.Scope, new Uri(AuthProvider.AuthorizeUrl), new Uri(AuthProvider.RedirectUrl)); // Code in this try block will run even if user is in the auth providers interface. } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Authenticate: Exception:"); for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException) { System.Diagnostics.Debug.WriteLine("Message:" + inner.Message); } // Denne vil kaste en ny exception? foreach (KeyValuePair<string, string> p in accounts[0].Properties) System.Diagnostics.Debug.WriteLine("Key:" + p.Key + " Value:" + p.Value); } // If there is a registered account the manual login will not be needed and this // and this else statement will be executed instead. //else // PerformAuth2TestRequests(accounts[0]); }
public HealthGraphTracker(IOAuth2Authenticator authenticator) { Authenticator = authenticator; _client = new Client(Authenticator); }
/// <summary> /// Handles the logic of the authentication with the OAuth2 Authentication provider /// </summary> /// <param name="auth">The authenticater</param> /// <param name="accounts">List of registered accounts for the choosen Service</param> void Authenticate(IOAuth2Authenticator auth, List <Account> accounts) { // Checks if there any accounts stored. // if (accounts.Count == 0) // { // EventHandler: When an auth is completed this will be executed. auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { try { AccountStore.Create().Save(eventArgs.Account, AuthProvider.Name); PerformAuth2TestRequests(eventArgs.Account); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } else { System.Diagnostics.Debug.WriteLine("Authenticate: Not Authenticated"); return; } }; auth.Error += (sender, eventArgs) => { System.Diagnostics.Debug.WriteLine("Authenticate: Error:" + eventArgs.Message); Exception ex = eventArgs.Exception; for (Exception inner = eventArgs.Exception; inner != null; inner = inner.InnerException) { System.Diagnostics.Debug.WriteLine("Message:" + inner.Message); } return; }; try { // This is were the user will meet the OAuth2 providers interface // When the auth is complete the EventHandler under the IF-statement will be run. auth.OAuth2Authenticator(AuthProvider.ClientId, AuthProvider.Scope, new Uri(AuthProvider.AuthorizeUrl), new Uri(AuthProvider.RedirectUrl)); // Code in this try block will run even if user is in the auth providers interface. } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Authenticate: Exception:"); for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException) { System.Diagnostics.Debug.WriteLine("Message:" + inner.Message); } // Denne vil kaste en ny exception? foreach (KeyValuePair <string, string> p in accounts[0].Properties) { System.Diagnostics.Debug.WriteLine("Key:" + p.Key + " Value:" + p.Value); } } // If there is a registered account the manual login will not be needed and this // and this else statement will be executed instead. //else // PerformAuth2TestRequests(accounts[0]); }