# Passkeys

> Usernameless passkey sign-up and sign-in, with the session cookie set for you.

From `docs/guide.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/guides/passkeys.

```go
pk, _ := passkey.New(svc, store, passkey.Config{
	RPID: "tensile.example", RPName: "Example", Origins: []string{"https://tensile.example"},
})
```

Sign-up starts with an app-chosen binding, such as a random value in a short-lived cookie, and carries the form's data in `State`:

```go
opts, err := pk.BeginFirstRegistration(ctx, userID, passkey.User{Name: email, Label: "This device", State: formJSON}, binding)
// …the browser client runs the ceremony and posts the credential…
cred, proof, err := pk.FinishRegistration(ctx, binding, body)
res, err := authhttp.SignIn(w, r, svc, proof, auth.StartOptions{Scopes: scopes}) // cred.State is formJSON
```

Sign-in is usernameless:

```go
opts, err := pk.BeginLogin(ctx, passkey.LoginOptions{Conditional: autofill})
proof, err := pk.FinishLogin(ctx, body)
res, err := authhttp.SignIn(w, r, svc, proof, auth.StartOptions{Scopes: scopesFor(proof.User)})
```

`authhttp.SignIn` sets the session cookie, with the device label ("Chrome on macOS") and user agent from the request. A passkey needs nothing more.
