Implemented methods for creating an authorization without having to specify an app clientid/clientsecret.

These methods will ONLY work with username/password Basic Auth.

Added a helper method to return a GitHub client using basic auth credentials as if you have both password and oauth token environment variables, you get credentials based on the oauth token.
This commit is contained in:
Henrik Andersson
2015-12-11 00:16:36 +10:00
parent 2c2ba0ce6d
commit 2152ba4d14
6 changed files with 254 additions and 0 deletions
+24
View File
@@ -36,6 +36,20 @@ namespace Octokit.Tests.Integration
return new Credentials(applicationClientId, applicationClientSecret);
});
static readonly Lazy<Credentials> _basicAuthCredentials = new Lazy<Credentials>(() =>
{
var githubUsername = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME");
UserName = githubUsername;
Organization = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBORGANIZATION");
var githubPassword = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD");
if (githubUsername == null || githubPassword == null)
return null;
return new Credentials(githubUsername, githubPassword);
});
static Helper()
{
// Force reading of environment variables.
@@ -51,6 +65,8 @@ namespace Octokit.Tests.Integration
public static Credentials ApplicationCredentials { get { return _oauthApplicationCredentials.Value; } }
public static Credentials BasicAuthCredentials { get { return _basicAuthCredentials.Value; } }
public static bool IsUsingToken
{
get
@@ -118,6 +134,14 @@ namespace Octokit.Tests.Integration
};
}
public static IGitHubClient GetBasicAuthClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = BasicAuthCredentials
};
}
public static GitHubClient GetAuthenticatedApplicationClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))