async void Login(PasswordBox obj) { LoggingIn = true; var secureString = ConvertToUnsecureString(obj.SecurePassword); var result = await githubApi.Authorize(new NetworkCredential(Username, secureString), new[] { Scopes.Repo }, "GitHub for Outlook"); settings.UpdateAuthInfo(result.Id, result.Token, Username); OnClose(); }
/// <summary> /// Logs into the GitHub API using the test account for integration testing. If there is a matching authorization for the given scopes from a previous test, it is reused /// </summary> /// <param name="scopes">The scopes to request access to</param> protected async Task Authorize(IEnumerable <Scopes> scopes = null) { if (Api.Context.Authorization == Authorization.Anonymous || (scopes != null && Api.Context.Authorization.Scopes != null && !Api.Context.Authorization.Scopes.Intersect(scopes).Any())) { var authorization = await Api.Authorize( new NetworkCredential(IntegrationTestParameters.GitHubUsername, IntegrationTestParameters.GitHubPassword), scopes, "IronGithub Integration Test"); lock (_lockObject) { Api.Context.Authorize(authorization); } } }
/// <summary> /// Logs into the GitHub API using the test account for integration testing. If there is a matching authorization for the given scopes from a previous test, it is reused /// </summary> /// <param name="scopes">The scopes to request access to</param> protected async Task Authorize(IEnumerable <Scopes> scopes = null) { var authorization = _authorizations.FirstOrDefault(x => x.Scopes.Matches(scopes)); if (authorization == null) { authorization = await Api.Authorize( new NetworkCredential(IntegrationTestParameters.GitHubUsername, IntegrationTestParameters.GitHubPassword), scopes, "IronGithub Integration Test"); _authorizations.Add(authorization); } else { Api.Context.Authorize(authorization); } }
async public static Task Auth(string accountName, GitHubApi api, IEnumerable <Scopes> scopes = null, string note = null) { var account = Load(accountName); var auth = account.Authorizations.FirstOrDefault(x => x.Scopes.Matches(scopes)); if (auth == null) { auth = await api.Authorize(account.Credential, scopes, note); auth.Invalidated += account.OnAuthorizationInvalidated; account.Authorizations.Add(auth); account.Save(); } else { api.Context.Authorize(auth); auth.Invalidated += account.OnAuthorizationInvalidated; } }