Files
octokit.net/Octokit/Authentication/BearerTokenAuthenticator.cs
Ryan Gribble 3b2be81486 Release v0.30 - Where Have You Been All My Life? (#1816)
* run FormatCode build task to fix whitespace/formatting

* correctly flag some GitHub Enterprise tests

* Add Release Notes

* tweak appveyor to not build branch in the repo, when a PR exists already

* travis to only build master branch and PRs

* output actual "dotnet run" command being executed for cake.frosting builds

* update latest Cake.Frosting

* use normal verbosity at the moment due to apparent conflict with "verbose" and latest SDK on appveyor

* try using double dash so dotnet executable doesnt look at --verbosity argument

* travis OSX couldn't download SDK 2.0.3 anymore, lets try the latest 2.1.300
2018-06-18 08:34:14 +10:00

24 lines
871 B
C#

using System;
using System.Globalization;
namespace Octokit.Internal
{
class BearerTokenAuthenticator : IAuthenticationHandler
{
public void Authenticate(IRequest request, Credentials credentials)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(credentials, nameof(credentials));
Ensure.ArgumentNotNull(credentials.Password, nameof(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);
}
}
}