Skip to content

Aded more documentation to the readme #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,84 @@ 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

```csharp

// in Program.cs or Startup.cs
services.AddPasswordlessSdk(options =>
{
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,
};
}
}

```

### Verify user

```csharp
[HttpGet]
[Route("/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
};
}
}
```



## Documentation

For a comprehensive list of examples, check out the [API
Expand Down