Skip to content

Commit

Permalink
Update readme (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz authored Sep 19, 2023
1 parent 5d6bc7d commit d5e19cc
Showing 1 changed file with 46 additions and 55 deletions.
101 changes: 46 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 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]
[Nuget Package][nuget-package]

Using the [.NET Core command-line interface (CLI) tools][dotnet-core-cli-tools]:

Expand Down Expand Up @@ -33,89 +33,80 @@ From within Visual Studio:
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)

#### 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<IActionResult> 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<string> { 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<string> { 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<IActionResult> 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].

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
Expand Down

0 comments on commit d5e19cc

Please sign in to comment.