mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-02 02:45:32 +00:00
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:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user