diff --git a/.github/workflows/relase.yml b/.github/workflows/relase.yml deleted file mode 100644 index 7686f1a..0000000 --- a/.github/workflows/relase.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Release to NuGet - -on: - release: - types: [published] - -jobs: - build: - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Setup dotnet - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a #v3.0.3 - - name: Build - run: dotnet build -c Release - - name: Test - run: dotnet test -c Release --no-build - - name: Pack nugets - run: dotnet pack -c Release --no-build --output . - - name: Push to NuGet - run: dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b985424 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: Release to NuGet + +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Setup dotnet + uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3 + + - name: Build + run: dotnet build --configuration Release + + - name: Test + run: > + dotnet test + --no-build + --framework net462 + --configuration Release + --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" + -- + RunConfiguration.CollectSourceInformation=true + + - name: Pack nugets + run: > + dotnet pack + --configuration Release + --no-build + --output . + + - name: Push to NuGet + run: > + dotnet nuget push *.nupkg + --source https://api.nuget.org/v3/index.json + --api-key ${{secrets.nuget_api_key}} diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7d60b99..3614527 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -22,11 +22,14 @@ jobs: clean_name: ${{steps.clean_branch_name.outputs.CLEAN_BRANCH_NAME}} steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + - name: Checkout + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + - name: Setup dotnet - uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a #v3.0.3 + uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3 # with: # dotnet-version: ${{ matrix.dotnet-version }} + # You can test your matrix by printing the current dotnet version - name: Display dotnet version run: dotnet --version @@ -35,13 +38,26 @@ jobs: run: dotnet restore --locked-mode - name: Build - run: dotnet build -f net6.0 --verbosity minimal --no-restore + run: > + dotnet build + --no-restore + --framework net6.0 + --configuration Release + --verbosity minimal - name: Check Format run: dotnet format --verify-no-changes --no-restore - name: Test with the dotnet CLI - run: dotnet test --no-build --no-restore --framework net6.0 --logger "trx;LogFileName=pw-test-results.trx" + run: > + dotnet test + --no-build + --no-restore + --framework net6.0 + --configuration Release + --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" + -- + RunConfiguration.CollectSourceInformation=true - id: clean_branch_name name: Clean Branch Name @@ -49,22 +65,16 @@ jobs: env: BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - - name: Report test results - uses: dorny/test-reporter@c9b3d0e2bd2a4e96aaf424dbaa31c46b42318226 # v1.6.0 - if: always() - with: - name: Test Results - path: "**/*-test-results.trx" - reporter: dotnet-trx - fail-on-error: true - build-framework: runs-on: windows-latest needs: build-dotnet steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + - name: Checkout + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + # - name: Setup dotnet # uses: setup msbuild? + - name: Display dotnet version run: | dotnet --version @@ -75,29 +85,39 @@ jobs: - name: Build # Don't specify a framework here so we build both .NET and .NET Framework so we can pack both - run: dotnet build --verbosity minimal --no-restore + run: > + dotnet build + --no-restore + --configuration Release + --verbosity minimal # Don't bother running formatting for this build - name: Test with the dotnet CLI # We will have already ran the tests on ubuntu, so only do .NET Framework ones here - run: dotnet test --no-build --no-restore --framework net462 --logger "trx;LogFileName=pw-framework-test-results.trx" - - - name: Report test results - uses: dorny/test-reporter@c9b3d0e2bd2a4e96aaf424dbaa31c46b42318226 # v1.6.0 - if: always() - with: - name: Test Results - path: "**/*-test-results.trx" - reporter: dotnet-trx - fail-on-error: true + run: > + dotnet test + --no-build + --no-restore + --framework net462 + --configuration Release + --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" + -- + RunConfiguration.CollectSourceInformation=true - name: Pack NuGet Packages - run: dotnet pack --no-build --version-suffix "ci-${{ env.CLEAN_BRANCH_NAME }}-${{ github.run_id }}" + run: > + dotnet pack + --no-build + --configuration Release + --version-suffix "ci-${{ env.CLEAN_BRANCH_NAME }}-${{ github.run_id }}" env: CLEAN_BRANCH_NAME: ${{needs.build-dotnet.outputs.clean_name}} - name: Publish NuGet Packages - run: dotnet nuget push **/*.nupkg --source https://nuget.pkg.github.com/passwordless/index.json --api-key ${{env.GITHUB_TOKEN}} + run: > + dotnet nuget push **/*.nupkg + --source https://nuget.pkg.github.com/passwordless/index.json + --api-key ${{env.GITHUB_TOKEN}} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Directory.Build.props b/Directory.Build.props index 6b9ec43..9edb06f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,10 +3,11 @@ net8.0 - false + false latest enable enable + nullable @@ -19,7 +20,7 @@ diff --git a/README.md b/README.md index 29953d0..463033f 100644 --- a/README.md +++ b/README.md @@ -1,124 +1,105 @@ # Passwordless .NET SDK -The official [Bitwarden Passwordless.dev](https://passwordless.dev/) .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+ (and soon .NET Framework 4.6.1+). +The official [Bitwarden Passwordless.dev](https://passwordless.dev) .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+, and .NET Framework 4.6.2+. ## Installation -[Nuget Package][nuget-package] +Install the [NuGet Package](https://nuget.org/packages/Passwordless): -Using the [.NET Core command-line interface (CLI) tools][dotnet-core-cli-tools]: +- Using the [.NET CLI](https://docs.microsoft.com/en-us/dotnet/core/tools): -```sh -dotnet add package Passwordless -``` - -Using the [NuGet Command Line Interface (CLI)][nuget-cli]: + ```sh + dotnet add package Passwordless + ``` -```sh -nuget install Passwordless -``` +- Using the [NuGet CLI](https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference): -Using the [Package Manager Console][package-manager-console]: + ```sh + nuget install Passwordless + ``` -```powershell -Install-Package Passwordless -``` +- Using the [Package Manager Console](https://docs.microsoft.com/en-us/nuget/tools/package-manager-console): -From within Visual Studio: + ```powershell + Install-Package Passwordless + ``` -1. Open the Solution Explorer. -2. Right-click on a project within your solution. -3. Click on *Manage NuGet Packages...* -4. Click on the *Browse* tab and search for "Passwordless". -5. Click on the Passwordless package, select the appropriate version in the - right-tab and click *Install*. +- From within Visual Studio: + 1. Open the Solution Explorer. + 2. Right-click on a project within your solution. + 3. Click on *Manage NuGet Packages...* + 4. Click on the *Browse* tab and search for "Passwordless". + 5. Click on the Passwordless package, select the appropriate version in the + right-tab and click *Install*. ## Getting started -Follow the [Get started guide](https://docs.passwordless.dev/guide/get-started.html) +💡 See the full [Getting started guide](https://docs.passwordless.dev/guide/get-started.html) in the official documentation. -#### Register to Dependency Injection +#### Register using Dependency Injection ```csharp - -// in Program.cs or Startup.cs +// In Program.cs or Startup.cs services.AddPasswordlessSdk(options => { - options.ApiSecret = "your_api_secret"; + options.ApiKey = "your_api_key"; + options.ApiSecret = "your_api_secret"; }); ``` ### Register a passkey ```csharp - [HttpGet("/create-token")] public async Task GetRegisterToken(string alias) { - - // Get existing userid from session or create a new user in your database - var userId = Guid.NewGuid().ToString(); - - // Options to give the Api - var payload = new RegisterOptions - { - UserId = userId, // your user id - Username = alias, // e.g. user email, is shown in browser ui - Aliases = new HashSet { alias } // Optional: Link this userid to an alias (e.g. email) - }; - - try - { - var token = await _passwordlessClient.CreateRegisterTokenAsync(payload); - - // return this token to the frontend - return Ok(token); - } - catch (PasswordlessApiException e) - { - return new JsonResult(e.Details) - { - StatusCode = (int)e.StatusCode, - }; - } + // Get existing userid from session or create a new user in your database + var userId = Guid.NewGuid().ToString(); + + // Provide the userid and an alias to link to this user + var payload = new RegisterOptions(userId, alias) + { + // Optional: Link this userid to an alias (e.g. email) + Aliases = new HashSet { alias } + }; + + try + { + var tokenRegistration = await _passwordlessClient.CreateRegisterTokenAsync(payload); + + // Return this token to the frontend + return Ok(tokenRegistration); + } + catch (PasswordlessApiException e) + { + return new JsonResult(e.Details) + { + StatusCode = (int?)e.StatusCode, + }; + } } - ``` ### Verify user ```csharp -[HttpGet] -[Route("/verify-signin")] +[HttpGet("/verify-signin")] public async Task VerifySignInToken(string token) { - try - { - var verifiedUser = await _passwordlessClient.VerifyTokenAsync(token); - // Sign the user in, set a cookie, etc, - return Ok(verifiedUser); - } - catch (PasswordlessApiException e) - { - return new JsonResult(e.Details) - { - StatusCode = (int)e.StatusCode - }; - } + try + { + var verifiedUser = await _passwordlessClient.VerifyTokenAsync(token); + + // Sign the user in, set a cookie, etc + return Ok(verifiedUser); + } + catch (PasswordlessApiException e) + { + return new JsonResult(e.Details) + { + StatusCode = (int?)e.StatusCode + }; + } } ``` - - - -## Documentation - -For a comprehensive list of examples, check out the [API -documentation][api-docs]. - - -[nuget-package]:https://www.nuget.org/packages/Passwordless/ -[api-docs]:https://docs.passwordless.dev/guide/get-started.html -[dotnet-core-cli-tools]: https://docs.microsoft.com/en-us/dotnet/core/tools/ -[nuget-cli]: https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference -[package-manager-console]: https://docs.microsoft.com/en-us/nuget/tools/package-manager-console diff --git a/src/Passwordless.Net/Models/AddAliasRequest.cs b/src/Passwordless.Net/Models/AddAliasRequest.cs index 62319c2..6eacc90 100644 --- a/src/Passwordless.Net/Models/AddAliasRequest.cs +++ b/src/Passwordless.Net/Models/AddAliasRequest.cs @@ -24,6 +24,7 @@ private AddAliasRequest(string userId, bool hashing = true) { UserId = userId ?? throw new ArgumentNullException(nameof(userId)); Hashing = hashing; + Aliases = new HashSet(); } public string UserId { get; } diff --git a/tests/Passwordless.Net.Tests/Passwordless.Net.Tests.csproj b/tests/Passwordless.Net.Tests/Passwordless.Net.Tests.csproj index 831bdb7..ab8df35 100644 --- a/tests/Passwordless.Net.Tests/Passwordless.Net.Tests.csproj +++ b/tests/Passwordless.Net.Tests/Passwordless.Net.Tests.csproj @@ -9,6 +9,7 @@ +