Skip to content

Commit 2ff9ebc

Browse files
authored
Aded more documentation to the readme (#14)
1 parent feaf789 commit 2ff9ebc

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,84 @@ From within Visual Studio:
3333
5. Click on the Passwordless package, select the appropriate version in the
3434
right-tab and click *Install*.
3535

36+
37+
## Getting started
38+
39+
Follow the [Get started guide](https://docs.passwordless.dev/guide/get-started.html)
40+
41+
#### Register to Dependency Injection
42+
43+
```csharp
44+
45+
// in Program.cs or Startup.cs
46+
services.AddPasswordlessSdk(options =>
47+
{
48+
options.ApiSecret = "your_api_secret";
49+
});
50+
51+
```
52+
### Register a passkey
53+
54+
```csharp
55+
56+
[HttpGet("/create-token")]
57+
public async Task<IActionResult> GetRegisterToken(string alias)
58+
{
59+
60+
// Get existing userid from session or create a new user in your database
61+
var userId = Guid.NewGuid().ToString();
62+
63+
// Options to give the Api
64+
var payload = new RegisterOptions
65+
{
66+
UserId = userId, // your user id
67+
Username = alias, // e.g. user email, is shown in browser ui
68+
Aliases = new HashSet<string> { alias } // Optional: Link this userid to an alias (e.g. email)
69+
};
70+
71+
try
72+
{
73+
var token = await _passwordlessClient.CreateRegisterTokenAsync(payload);
74+
75+
// return this token to the frontend
76+
return Ok(token);
77+
}
78+
catch (PasswordlessApiException e)
79+
{
80+
return new JsonResult(e.Details)
81+
{
82+
StatusCode = (int)e.StatusCode,
83+
};
84+
}
85+
}
86+
87+
```
88+
89+
### Verify user
90+
91+
```csharp
92+
[HttpGet]
93+
[Route("/verify-signin")]
94+
public async Task<IActionResult> VerifySignInToken(string token)
95+
{
96+
try
97+
{
98+
var verifiedUser = await _passwordlessClient.VerifyTokenAsync(token);
99+
// Sign the user in, set a cookie, etc,
100+
return Ok(verifiedUser);
101+
}
102+
catch (PasswordlessApiException e)
103+
{
104+
return new JsonResult(e.Details)
105+
{
106+
StatusCode = (int)e.StatusCode
107+
};
108+
}
109+
}
110+
```
111+
112+
113+
36114
## Documentation
37115

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

0 commit comments

Comments
 (0)