From e92ea28e816d4f60cc76f016d64c0bf488265838 Mon Sep 17 00:00:00 2001 From: Jacob Reimers Date: Mon, 31 May 2021 21:53:35 +0200 Subject: [PATCH] Add documentation. --- src/simpleauth.client/DeviceTokenRequest.cs | 25 +++++++++++++ src/simpleauth.client/PkceBuilder.cs | 8 ++++ src/simpleauth.client/TokenCredentials.cs | 4 ++ src/simpleauth.client/TokenRequest.cs | 37 ++++++++++--------- .../Repositories/IDeviceAuthorizationStore.cs | 34 +++++++++++++++++ .../Requests/DeviceAuthorizationRequest.cs | 10 +++++ .../Responses/DeviceAuthorizationResponse.cs | 3 ++ .../Api/Device/DeviceAuthorizationActions.cs | 18 +++++++++ .../DeviceAuthorizationController.cs | 32 ++++++++++++++-- .../Controllers/DeviceController.cs | 19 ++++++++++ src/simpleauth/Controllers/TokenController.cs | 2 +- src/simpleauth/RuntimeSettings.cs | 3 ++ 12 files changed, 172 insertions(+), 23 deletions(-) create mode 100644 src/simpleauth.client/DeviceTokenRequest.cs diff --git a/src/simpleauth.client/DeviceTokenRequest.cs b/src/simpleauth.client/DeviceTokenRequest.cs new file mode 100644 index 000000000..fca97c79c --- /dev/null +++ b/src/simpleauth.client/DeviceTokenRequest.cs @@ -0,0 +1,25 @@ +namespace SimpleAuth.Client +{ + using System.Collections.Generic; + + /// + /// Defines the device token request. + /// + public record DeviceTokenRequest : TokenRequest + { + /// + /// Initializes a new instance of the record. + /// + /// The request form. + /// The polling interval. + public DeviceTokenRequest(Dictionary form, int interval) : base(form) + { + Interval = interval; + } + + /// + /// Gets the polling interval. + /// + public int Interval { get; } + } +} \ No newline at end of file diff --git a/src/simpleauth.client/PkceBuilder.cs b/src/simpleauth.client/PkceBuilder.cs index 535350968..a029c3e29 100644 --- a/src/simpleauth.client/PkceBuilder.cs +++ b/src/simpleauth.client/PkceBuilder.cs @@ -18,10 +18,18 @@ namespace SimpleAuth.Client using System.Text; using SimpleAuth.Shared.Models; + /// + /// Defines the PKCE builder. + /// public static class PkceBuilder { private static readonly Random Random = new(); + /// + /// Builds a PKCE challenge. + /// + /// The challenge method. + /// A instance. public static Pkce BuildPkce(this string method) { var codeVerifier = GetCodeVerifier(); diff --git a/src/simpleauth.client/TokenCredentials.cs b/src/simpleauth.client/TokenCredentials.cs index 9c9065103..1d89a0fe7 100644 --- a/src/simpleauth.client/TokenCredentials.cs +++ b/src/simpleauth.client/TokenCredentials.cs @@ -124,6 +124,10 @@ public static TokenCredentials FromClientSecret(string clientAssertion, string c return new TokenCredentials(dict); } + /// + /// Creates the credentials as a device. + /// + /// public static TokenCredentials AsDevice() { return new(new Dictionary()); diff --git a/src/simpleauth.client/TokenRequest.cs b/src/simpleauth.client/TokenRequest.cs index 7fc2b176c..9b54d5d52 100644 --- a/src/simpleauth.client/TokenRequest.cs +++ b/src/simpleauth.client/TokenRequest.cs @@ -27,6 +27,10 @@ public record TokenRequest : IEnumerable> { private readonly Dictionary _form; + /// + /// Initializes a new instance of the record. + /// + /// protected internal TokenRequest(Dictionary form) { _form = form; @@ -212,18 +216,13 @@ public static TokenRequest FromPassword(string userName, string password, string return FromPassword(userName, password, scopes, new[] { amrValue }); } - /// - public IEnumerator> GetEnumerator() - { - return _form.GetEnumerator(); - } - - /// - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - + /// + /// Creates a request from the device code. + /// + /// The client id. + /// The device code. + /// The polling interval. + /// A instance. public static TokenRequest FromDeviceCode(string clientId, string deviceCode, int interval) { var dictionary = new Dictionary @@ -234,15 +233,17 @@ public static TokenRequest FromDeviceCode(string clientId, string deviceCode, in }; return new DeviceTokenRequest(dictionary, interval); } - } - public record DeviceTokenRequest : TokenRequest - { - public DeviceTokenRequest(Dictionary form, int interval) : base(form) + /// + public IEnumerator> GetEnumerator() { - Interval = interval; + return _form.GetEnumerator(); } - public int Interval { get; } + /// + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } } \ No newline at end of file diff --git a/src/simpleauth.shared/Repositories/IDeviceAuthorizationStore.cs b/src/simpleauth.shared/Repositories/IDeviceAuthorizationStore.cs index 96b1ccf1c..652470625 100644 --- a/src/simpleauth.shared/Repositories/IDeviceAuthorizationStore.cs +++ b/src/simpleauth.shared/Repositories/IDeviceAuthorizationStore.cs @@ -5,16 +5,50 @@ using SimpleAuth.Shared.Requests; using SimpleAuth.Shared.Responses; + /// + /// Defines the device authorization store interface. + /// public interface IDeviceAuthorizationStore { + /// + /// Gets the for the user code. + /// + /// The user code. + /// The for the async operation. + /// A as an async operation. public Task> Get(string userCode, CancellationToken cancellationToken = default); + /// + /// Gets the for the device code. + /// + /// The client id. + /// The device code. + /// The for the async operation. + /// A as an async operation. public Task> Get(string clientId, string deviceCode, CancellationToken cancellationToken = default); + /// + /// Approves the authorization request. + /// + /// The user code. + /// The for the async operation. + /// An as an async operation. public Task