From 53cc6896fa3b9b3d93c11c7ec8e231f952a8019a Mon Sep 17 00:00:00 2001 From: V <75526192+hakuna-matata-in@users.noreply.github.com> Date: Wed, 8 Sep 2021 01:34:21 +0530 Subject: [PATCH 1/6] Create build.yml --- .github/workflows/build.yml | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..cf87fa2e1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,48 @@ +name: Build +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build + runs-on: windows-latest + steps: + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 1.11 + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~\sonar\cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache SonarCloud scanner + id: cache-sonar-scanner + uses: actions/cache@v1 + with: + path: .\.sonar\scanner + key: ${{ runner.os }}-sonar-scanner + restore-keys: ${{ runner.os }}-sonar-scanner + - name: Install SonarCloud scanner + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' + shell: powershell + run: | + New-Item -Path .\.sonar\scanner -ItemType Directory + dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + shell: powershell + run: | + .\.sonar\scanner\dotnet-sonarscanner begin /k:"hakuna-matata-in_auth0.net" /o:"hakuna-matata-in" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" + dotnet restore Auth0.Net.sln + dotnet build Auth0.Net.sln + .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" From b3350eb072f1c7f893b65b322e9f2a573177fc1c Mon Sep 17 00:00:00 2001 From: Vijayakumar Natarajan <75526192+hakuna-matata-in@users.noreply.github.com> Date: Wed, 8 Sep 2021 02:32:41 +0530 Subject: [PATCH 2/6] Added prompt api client --- .github/workflows/build.yml | 48 ---------------- .../Clients/PromptsClient.cs | 57 +++++++++++++++++++ .../ManagementApiClient.cs | 6 ++ src/Auth0.ManagementApi/Models/Prompt.cs | 29 ++++++++++ .../Models/PromptUpdateRequest.cs | 9 +++ .../PromptsTests.cs | 37 ++++++++++++ 6 files changed, 138 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 src/Auth0.ManagementApi/Clients/PromptsClient.cs create mode 100644 src/Auth0.ManagementApi/Models/Prompt.cs create mode 100644 src/Auth0.ManagementApi/Models/PromptUpdateRequest.cs create mode 100644 tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index cf87fa2e1..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Build -on: - push: - branches: - - master - pull_request: - types: [opened, synchronize, reopened] -jobs: - build: - name: Build - runs-on: windows-latest - steps: - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 1.11 - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Cache SonarCloud packages - uses: actions/cache@v1 - with: - path: ~\sonar\cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Cache SonarCloud scanner - id: cache-sonar-scanner - uses: actions/cache@v1 - with: - path: .\.sonar\scanner - key: ${{ runner.os }}-sonar-scanner - restore-keys: ${{ runner.os }}-sonar-scanner - - name: Install SonarCloud scanner - if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' - shell: powershell - run: | - New-Item -Path .\.sonar\scanner -ItemType Directory - dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner - - name: Build and analyze - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - shell: powershell - run: | - .\.sonar\scanner\dotnet-sonarscanner begin /k:"hakuna-matata-in_auth0.net" /o:"hakuna-matata-in" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" - dotnet restore Auth0.Net.sln - dotnet build Auth0.Net.sln - .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" diff --git a/src/Auth0.ManagementApi/Clients/PromptsClient.cs b/src/Auth0.ManagementApi/Clients/PromptsClient.cs new file mode 100644 index 000000000..e87bfb52d --- /dev/null +++ b/src/Auth0.ManagementApi/Clients/PromptsClient.cs @@ -0,0 +1,57 @@ +using Auth0.ManagementApi.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + + +namespace Auth0.ManagementApi.Clients +{ + /// + /// Contains methods to access the /prompts endpoints. + /// + public class PromptsClient : BaseClient + { + private const string PromptsBasePath = "prompts"; + /// + /// Initializes a new instance on + /// + /// used to make all API calls. + /// of the endpoint to use in making API calls. + /// Dictionary containing default headers included with every request this client makes. + public PromptsClient(IManagementConnection connection, Uri baseUri, IDictionary defaultHeaders) + : base(connection, baseUri, defaultHeaders) + { + } + + /// + /// Get prompts settings + /// + /// + /// Get prompts settings + /// + /// The cancellation token to cancel operation. + /// A instance containing the information about the prompt settings. + public Task GetAsync(CancellationToken cancellationToken = default) + { + return Connection.GetAsync(BuildUri($"{PromptsBasePath}"), DefaultHeaders, cancellationToken: cancellationToken); + } + + + /// + /// Update prompts settings. + /// + /// + /// Update prompts settings. + /// + /// Specifies prompt setting values that are to be updated. + /// The cancellation token to cancel operation. + /// The that was updated. + public Task UpdateAsync(PromptUpdateRequest request, CancellationToken cancellationToken = default) + { + return Connection.SendAsync(new HttpMethod("PATCH"), BuildUri($"{PromptsBasePath}"), request, DefaultHeaders, cancellationToken: cancellationToken); + } + } +} diff --git a/src/Auth0.ManagementApi/ManagementApiClient.cs b/src/Auth0.ManagementApi/ManagementApiClient.cs index 05fa064c9..60a2859f7 100644 --- a/src/Auth0.ManagementApi/ManagementApiClient.cs +++ b/src/Auth0.ManagementApi/ManagementApiClient.cs @@ -91,6 +91,11 @@ public class ManagementApiClient : IDisposable /// public OrganizationsClient Organizations { get; } + /// + /// Contains all the methods to call the /prompts endpoints. + /// + public PromptsClient Prompts { get; } + /// /// Contains all the methods to call the /resource-servers endpoints. /// @@ -171,6 +176,7 @@ public ManagementApiClient(string token, Uri baseUri, IManagementConnection mana Jobs = new JobsClient(managementConnection, baseUri, defaultHeaders); Logs = new LogsClient(managementConnection, baseUri, defaultHeaders); LogStreams = new LogStreamsClient(managementConnection, baseUri, defaultHeaders); + Prompts = new PromptsClient(managementConnection, baseUri, defaultHeaders); Organizations = new OrganizationsClient(managementConnection, baseUri, defaultHeaders); ResourceServers = new ResourceServersClient(managementConnection, baseUri, defaultHeaders); Roles = new RolesClient(managementConnection, baseUri, defaultHeaders); diff --git a/src/Auth0.ManagementApi/Models/Prompt.cs b/src/Auth0.ManagementApi/Models/Prompt.cs new file mode 100644 index 000000000..643edb553 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/Prompt.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using System; + +namespace Auth0.ManagementApi.Models +{ + /// + /// Represents Prompt Settings. + /// + public class Prompt + { + /// + /// Which login experience to use. Can be new or classic + /// + [JsonProperty("universal_login_experience")] + public string UniversalLoginExperience { get; set; } + + /// + /// Whether identifier first is enabled or not. + /// + [JsonProperty("identifier_first")] + public bool IdentifierFirst { get; set; } + + /// + /// Use WebAuthn with Device Biometrics as the first authentication factor + /// + [JsonProperty("webauthn_platform_first_factor")] + public bool WebAuthnPlatformFirstFactor { get; set; } + } +} diff --git a/src/Auth0.ManagementApi/Models/PromptUpdateRequest.cs b/src/Auth0.ManagementApi/Models/PromptUpdateRequest.cs new file mode 100644 index 000000000..dea506ae4 --- /dev/null +++ b/src/Auth0.ManagementApi/Models/PromptUpdateRequest.cs @@ -0,0 +1,9 @@ +namespace Auth0.ManagementApi.Models +{ + /// + /// Request configuration for updating prompt settings. + /// + public class PromptUpdateRequest : Prompt + { + } +} diff --git a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs new file mode 100644 index 000000000..908c9bb8b --- /dev/null +++ b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs @@ -0,0 +1,37 @@ +using Auth0.ManagementApi.Models; +using Auth0.Tests.Shared; +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xunit; + + +namespace Auth0.ManagementApi.IntegrationTests +{ + public class PromptsTests : TestBase, IAsyncLifetime + { + private ManagementApiClient _apiClient; + + public async Task InitializeAsync() + { + string token = await GenerateManagementApiToken(); + + _apiClient = new ManagementApiClient(token, GetVariable("AUTH0_MANAGEMENT_API_URL"), new HttpClientManagementConnection(options: new HttpClientManagementConnectionOptions { NumberOfHttpRetries = 9 })); + } + + public async Task DisposeAsync() + { + _apiClient.Dispose(); + return Task.CompletedTask; + } + + [Fact] + public async Task Test_get_prompts() + { + var prompts = await _apiClient.Prompts.GetAsync(); + prompts.Should().NotBeNull(); + } + + } +} From 11ecdef0feb20767a95cecf3964744a221f550f5 Mon Sep 17 00:00:00 2001 From: Frederik Date: Wed, 8 Sep 2021 09:24:57 +0200 Subject: [PATCH 3/6] Move Prompts models --- src/Auth0.ManagementApi/Clients/PromptsClient.cs | 1 + src/Auth0.ManagementApi/Models/{ => Prompts}/Prompt.cs | 3 +-- .../Models/{ => Prompts}/PromptUpdateRequest.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/Auth0.ManagementApi/Models/{ => Prompts}/Prompt.cs (94%) rename src/Auth0.ManagementApi/Models/{ => Prompts}/PromptUpdateRequest.cs (76%) diff --git a/src/Auth0.ManagementApi/Clients/PromptsClient.cs b/src/Auth0.ManagementApi/Clients/PromptsClient.cs index e87bfb52d..35e6cbcd5 100644 --- a/src/Auth0.ManagementApi/Clients/PromptsClient.cs +++ b/src/Auth0.ManagementApi/Clients/PromptsClient.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Auth0.ManagementApi.Models.Prompts; namespace Auth0.ManagementApi.Clients diff --git a/src/Auth0.ManagementApi/Models/Prompt.cs b/src/Auth0.ManagementApi/Models/Prompts/Prompt.cs similarity index 94% rename from src/Auth0.ManagementApi/Models/Prompt.cs rename to src/Auth0.ManagementApi/Models/Prompts/Prompt.cs index 643edb553..a062e6a5b 100644 --- a/src/Auth0.ManagementApi/Models/Prompt.cs +++ b/src/Auth0.ManagementApi/Models/Prompts/Prompt.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; -using System; -namespace Auth0.ManagementApi.Models +namespace Auth0.ManagementApi.Models.Prompts { /// /// Represents Prompt Settings. diff --git a/src/Auth0.ManagementApi/Models/PromptUpdateRequest.cs b/src/Auth0.ManagementApi/Models/Prompts/PromptUpdateRequest.cs similarity index 76% rename from src/Auth0.ManagementApi/Models/PromptUpdateRequest.cs rename to src/Auth0.ManagementApi/Models/Prompts/PromptUpdateRequest.cs index dea506ae4..08ae88602 100644 --- a/src/Auth0.ManagementApi/Models/PromptUpdateRequest.cs +++ b/src/Auth0.ManagementApi/Models/Prompts/PromptUpdateRequest.cs @@ -1,4 +1,4 @@ -namespace Auth0.ManagementApi.Models +namespace Auth0.ManagementApi.Models.Prompts { /// /// Request configuration for updating prompt settings. From 0f47b17e46ec3662f28d4895e9dc8a931f8c5af2 Mon Sep 17 00:00:00 2001 From: Frederik Date: Wed, 8 Sep 2021 09:25:12 +0200 Subject: [PATCH 4/6] Ensure tests compile successfully --- tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs index 908c9bb8b..e0e5cd4e7 100644 --- a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs +++ b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs @@ -1,8 +1,5 @@ -using Auth0.ManagementApi.Models; -using Auth0.Tests.Shared; +using Auth0.Tests.Shared; using FluentAssertions; -using System; -using System.Collections.Generic; using System.Threading.Tasks; using Xunit; @@ -20,7 +17,7 @@ public async Task InitializeAsync() _apiClient = new ManagementApiClient(token, GetVariable("AUTH0_MANAGEMENT_API_URL"), new HttpClientManagementConnection(options: new HttpClientManagementConnectionOptions { NumberOfHttpRetries = 9 })); } - public async Task DisposeAsync() + public Task DisposeAsync() { _apiClient.Dispose(); return Task.CompletedTask; From ac661a71b37689468f804292ccdeeebe916663fa Mon Sep 17 00:00:00 2001 From: Frederik Date: Wed, 8 Sep 2021 09:28:13 +0200 Subject: [PATCH 5/6] Remove whitespaces --- src/Auth0.ManagementApi/Clients/PromptsClient.cs | 6 +----- tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Auth0.ManagementApi/Clients/PromptsClient.cs b/src/Auth0.ManagementApi/Clients/PromptsClient.cs index 35e6cbcd5..a1d2317e2 100644 --- a/src/Auth0.ManagementApi/Clients/PromptsClient.cs +++ b/src/Auth0.ManagementApi/Clients/PromptsClient.cs @@ -1,13 +1,10 @@ -using Auth0.ManagementApi.Models; -using System; +using System; using System.Collections.Generic; -using System.IO; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Auth0.ManagementApi.Models.Prompts; - namespace Auth0.ManagementApi.Clients { /// @@ -40,7 +37,6 @@ public Task GetAsync(CancellationToken cancellationToken = default) return Connection.GetAsync(BuildUri($"{PromptsBasePath}"), DefaultHeaders, cancellationToken: cancellationToken); } - /// /// Update prompts settings. /// diff --git a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs index e0e5cd4e7..10a6fa579 100644 --- a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs +++ b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs @@ -3,13 +3,11 @@ using System.Threading.Tasks; using Xunit; - namespace Auth0.ManagementApi.IntegrationTests { public class PromptsTests : TestBase, IAsyncLifetime { private ManagementApiClient _apiClient; - public async Task InitializeAsync() { string token = await GenerateManagementApiToken(); @@ -29,6 +27,5 @@ public async Task Test_get_prompts() var prompts = await _apiClient.Prompts.GetAsync(); prompts.Should().NotBeNull(); } - } } From da0b296fa8465b3b215ba286db2b3d82c4e26cf0 Mon Sep 17 00:00:00 2001 From: Frederik Date: Wed, 8 Sep 2021 09:36:22 +0200 Subject: [PATCH 6/6] Add test for Prompts.UpdateAsync --- .../PromptsTests.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs index 10a6fa579..963799733 100644 --- a/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs +++ b/tests/Auth0.ManagementApi.IntegrationTests/PromptsTests.cs @@ -1,6 +1,7 @@ using Auth0.Tests.Shared; using FluentAssertions; using System.Threading.Tasks; +using Auth0.ManagementApi.Models.Prompts; using Xunit; namespace Auth0.ManagementApi.IntegrationTests @@ -22,10 +23,25 @@ public Task DisposeAsync() } [Fact] - public async Task Test_get_prompts() + public async Task Test_get_and_update_prompts() { var prompts = await _apiClient.Prompts.GetAsync(); prompts.Should().NotBeNull(); + + var originalExperience = prompts.UniversalLoginExperience; + var newExperience = originalExperience == "classic" ? "new" : "classic"; + + await _apiClient.Prompts.UpdateAsync(new PromptUpdateRequest {UniversalLoginExperience = newExperience }); + + prompts = await _apiClient.Prompts.GetAsync(); + prompts.Should().NotBeNull(); + prompts.UniversalLoginExperience.Should().Be(newExperience); + + await _apiClient.Prompts.UpdateAsync(new PromptUpdateRequest { UniversalLoginExperience = originalExperience }); + + prompts = await _apiClient.Prompts.GetAsync(); + prompts.Should().NotBeNull(); + prompts.UniversalLoginExperience.Should().Be(originalExperience); } } }