mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
Adding support for the Device Flow Oauth authentication pattern (#2310)
Adding support for the Device Flow Oauth authentication pattern
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to create an Oauth device flow initiation request.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class OauthDeviceFlowRequest
|
||||
: RequestParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an instance of the OAuth login request with the required parameter.
|
||||
/// </summary>
|
||||
/// <param name="clientId">The client Id you received from GitHub when you registered the application.</param>
|
||||
public OauthDeviceFlowRequest(string clientId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
|
||||
|
||||
ClientId = clientId;
|
||||
Scopes = new Collection<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The client Id you received from GitHub when you registered the application.
|
||||
/// </summary>
|
||||
[Parameter(Key = "client_id")]
|
||||
public string ClientId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A set of scopes to request. If not provided, scope defaults to an empty list of scopes for users that don’t
|
||||
/// have a valid token for the app. For users who do already have a valid token for the app, the user won't be
|
||||
/// shown the OAuth authorization page with the list of scopes. Instead, this step of the flow will
|
||||
/// automatically complete with the same scopes that were used last time the user completed the flow.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <see href="https://developer.github.com/v3/oauth/#scopes">scopes documentation</see> for more
|
||||
/// information about scopes.
|
||||
/// </remarks>
|
||||
[Parameter(Key = "scope")]
|
||||
public Collection<string> Scopes { get; private set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "ClientId: {0}, Scopes: {1}", ClientId, Scopes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to create an Oauth login request for the device flow.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
internal class OauthTokenRequestForDeviceFlow : RequestParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an instance of the OAuth login request with the required parameter.
|
||||
/// </summary>
|
||||
/// <param name="clientId">The client Id you received from GitHub when you registered the application.</param>
|
||||
/// <param name="deviceCode">The device code you received from the device flow initiation call.</param>
|
||||
public OauthTokenRequestForDeviceFlow(string clientId, string deviceCode)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
|
||||
Ensure.ArgumentNotNullOrEmptyString(deviceCode, nameof(deviceCode));
|
||||
|
||||
ClientId = clientId;
|
||||
DeviceCode = deviceCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The client Id you received from GitHub when you registered the application.
|
||||
/// </summary>
|
||||
[Parameter(Key = "client_id")]
|
||||
public string ClientId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The device code you received from the device flow initiation call.
|
||||
/// </summary>
|
||||
[Parameter(Key = "device_code")]
|
||||
public string DeviceCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The authorization grant type.
|
||||
/// </summary>
|
||||
[Parameter(Key = "grant_type")]
|
||||
public string GrantType => "urn:ietf:params:oauth:grant-type:device_code";
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "ClientId: {0}, DeviceCode: {1}",
|
||||
ClientId,
|
||||
DeviceCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user