Skip to content
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

Improve documentation #157

Merged
merged 3 commits into from
Oct 6, 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
40 changes: 13 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ supporting the storage and retrieval of the credential and authenticator structs
The following examples show some basic use cases of the library. For consistency sake the following variables are used
to denote specific things:

- Variable `w`: the `webauthn.WebAuthn` instance you initialize elsewhere in your code
- Variable `webAuthn`: the `webauthn.WebAuthn` instance you initialize elsewhere in your code
- Variable `datastore`: the pseudocode backend service that stores your webauthn session data and users such as PostgreSQL
- Variable `session`: the webauthn.SessionData object
- Variable `user`: your webauthn.User implementation
Expand All @@ -75,7 +75,7 @@ import (
)

var (
w *webauthn.WebAuthn
webAuthn *webauthn.WebAuthn
err error
)

Expand All @@ -87,7 +87,7 @@ func main() {
RPOrigins: []string{"https://login.go-webauthn.local"}, // The origin URLs allowed for WebAuthn requests
}

if w, err = webauthn.New(wconfig); err != nil {
if webAuthn, err = webauthn.New(wconfig); err != nil {
fmt.Println(err)
}
}
Expand All @@ -100,39 +100,32 @@ package example

func BeginRegistration(w http.ResponseWriter, r *http.Request) {
user := datastore.GetUser() // Find or create the new user
options, session, err := web.BeginRegistration(user)
options, session, err := webAuthn.BeginRegistration(user)
// handle errors if present
// store the sessionData values
JSONResponse(w, options, http.StatusOK) // return the options generated
// options.publicKey contain our registration options
}

func FinishRegistration(w http.ResponseWriter, r *http.Request) {
response, err := protocol.ParseCredentialCreationResponseBody(r.Body)
if err != nil {
// Handle Error and return.

return
}

user := datastore.GetUser() // Get the user

// Get the session data stored from the function above
session := datastore.GetSession()

credential, err := w.CreateCredential(user, session, response)
credential, err := webAuthn.FinishRegistration(user, session, r)
if err != nil {
// Handle Error and return.

return
}

// If creation was successful, store the credential object
JSONResponse(w, "Registration Success", http.StatusOK) // Handle next steps

// Pseudocode to add the user credential.
user.AddCredential(credential)
datastore.SaveUser(user)

JSONResponse(w, "Registration Success", http.StatusOK) // Handle next steps
}
```

Expand All @@ -144,7 +137,7 @@ package example
func BeginLogin(w http.ResponseWriter, r *http.Request) {
user := datastore.GetUser() // Find the user

options, session, err := w.BeginLogin(user)
options, session, err := webAuthn.BeginLogin(user)
if err != nil {
// Handle Error and return.

Expand All @@ -159,19 +152,12 @@ func BeginLogin(w http.ResponseWriter, r *http.Request) {
}

func FinishLogin(w http.ResponseWriter, r *http.Request) {
response, err := protocol.ParseCredentialRequestResponseBody(r.Body)
if err != nil {
// Handle Error and return.

return
}

user := datastore.GetUser() // Get the user

// Get the session data stored from the function above
session := datastore.GetSession()

credential, err := w.ValidateLogin(user, session, response)
credential, err := webAuthn.FinishLogin(user, session, r)
if err != nil {
// Handle Error and return.

Expand Down Expand Up @@ -200,7 +186,7 @@ import (
"github.com/go-webauthn/webauthn/webauthn"
)

var w webauthn.WebAuthn // init this in your init function
var webAuthn webauthn.WebAuthn // init this in your init function

func beginRegistration() {
// Updating the AuthenticatorSelection options.
Expand All @@ -216,7 +202,7 @@ func beginRegistration() {
conveyancePref := protocol.PreferNoAttestation

user := datastore.GetUser() // Get the user
opts, session, err := w.BeginRegistration(user, webauthn.WithAuthenticatorSelection(authSelect), webauthn.WithConveyancePreference(conveyancePref))
opts, session, err := webAuthn.BeginRegistration(user, webauthn.WithAuthenticatorSelection(authSelect), webauthn.WithConveyancePreference(conveyancePref))

// Handle next steps
}
Expand All @@ -234,7 +220,7 @@ import (
"github.com/go-webauthn/webauthn/webauthn"
)

var w webauthn.WebAuthn // init this in your init function
var webAuthn webauthn.WebAuthn // init this in your init function

func beginLogin() {
// Updating the AuthenticatorSelection options.
Expand Down Expand Up @@ -288,7 +274,7 @@ func main() {
},
}

w, err := webauthn.New(wconfig)
webAuthn, err := webauthn.New(wconfig)
if err != nil {
fmt.Println(err)
}
Expand Down