forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from adriangodong/master
Merge Adrian Godong work into my master branch.
- Loading branch information
Showing
18 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
public interface IObservableAccessTokensClient | ||
{ | ||
IObservable<AccessToken> Create(int installationId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Octokit.Reactive | ||
{ | ||
public interface IObservableInstallationsClient | ||
{ | ||
IObservableAccessTokensClient AccessTokens { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
class ObservableAccessTokensClient : IObservableAccessTokensClient | ||
{ | ||
readonly IAccessTokensClient _client; | ||
readonly IConnection _connection; | ||
|
||
public ObservableAccessTokensClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Installations.AccessTokens; | ||
_connection = client.Connection; | ||
} | ||
|
||
public IObservable<AccessToken> Create(int installationId) | ||
{ | ||
return _client.Create(installationId).ToObservable(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Octokit.Reactive | ||
{ | ||
class ObservableInstallationsClient : IObservableInstallationsClient | ||
{ | ||
readonly IInstallationsClient _client; | ||
readonly IConnection _connection; | ||
|
||
public ObservableInstallationsClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Installations; | ||
_connection = client.Connection; | ||
AccessTokens = new ObservableAccessTokensClient(client); | ||
} | ||
|
||
public IObservableAccessTokensClient AccessTokens { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Octokit.Internal | ||
{ | ||
class BearerTokenAuthenticator: IAuthenticationHandler | ||
{ | ||
public void Authenticate(IRequest request, Credentials credentials) | ||
{ | ||
Ensure.ArgumentNotNull(request, "request"); | ||
Ensure.ArgumentNotNull(credentials, "credentials"); | ||
Ensure.ArgumentNotNull(credentials.Password, "credentials.Password"); | ||
|
||
if (credentials.Login != null) | ||
{ | ||
throw new InvalidOperationException("The Login is not null for a token authentication request. You " + | ||
"probably did something wrong."); | ||
} | ||
|
||
request.Headers["Authorization"] = string.Format(CultureInfo.InvariantCulture, "Bearer {0}", credentials.Password); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
class AccessTokensClient : ApiClient, IAccessTokensClient | ||
{ | ||
private const string AcceptHeader = "application/vnd.github.machine-man-preview+json"; | ||
|
||
public AccessTokensClient(IApiConnection apiConnection) : base(apiConnection) | ||
{ | ||
} | ||
|
||
public Task<AccessToken> Create(int installationId) | ||
{ | ||
return ApiConnection.Post<AccessToken>(ApiUrls.AccessTokens(installationId), null, AcceptHeader); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
public interface IAccessTokensClient | ||
{ | ||
Task<AccessToken> Create(int installationId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Octokit | ||
{ | ||
public interface IInstallationsClient | ||
{ | ||
IAccessTokensClient AccessTokens { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Octokit | ||
{ | ||
class InstallationsClient : ApiClient, IInstallationsClient | ||
{ | ||
public InstallationsClient(IApiConnection apiConnection) : base(apiConnection) | ||
{ | ||
AccessTokens = new AccessTokensClient(apiConnection); | ||
} | ||
|
||
public IAccessTokensClient AccessTokens { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
namespace Octokit | ||
{ | ||
[DebuggerDisplay("{DebuggerDisplay,nq}")] | ||
public class AccessToken | ||
{ | ||
public AccessToken() { } | ||
|
||
public AccessToken(string token, DateTime expiresAt) | ||
{ | ||
Token = token; | ||
ExpiresAt = expiresAt; | ||
} | ||
|
||
public string Token { get; protected set; } | ||
public DateTime ExpiresAt { get; protected set; } | ||
|
||
internal string DebuggerDisplay | ||
{ | ||
get | ||
{ | ||
return string.Format(CultureInfo.InvariantCulture, "Token: {0}, ExpiresAt: {1}", Token, ExpiresAt); | ||
} | ||
} | ||
} | ||
} |