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 1 commit
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
Next Next commit
Clean up some inconsistencies
This changes the variable names of the examples slightly to use the commonly
used w for the ResponseWriter and removes the clash with the WebAuthn instance.

Signed-off-by: Robin Brandt <[email protected]>
  • Loading branch information
robinbrandt committed Aug 12, 2023
commit 15048d4ddc60adda4e1289d2c51c605302800e10
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -57,7 +57,7 @@ import (
)

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

Expand All @@ -69,7 +69,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 @@ -82,7 +82,7 @@ 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
Expand All @@ -102,19 +102,19 @@ func FinishRegistration(w http.ResponseWriter, r *http.Request) {
// Get the session data stored from the function above
session := datastore.GetSession()

credential, err := w.CreateCredential(user, session, response)
credential, err := webAuthn.CreateCredential(user, session, response)
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 @@ -126,7 +126,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 @@ -153,7 +153,7 @@ func FinishLogin(w http.ResponseWriter, r *http.Request) {
// Get the session data stored from the function above
session := datastore.GetSession()

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

Expand Down Expand Up @@ -182,7 +182,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 @@ -198,7 +198,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 @@ -216,7 +216,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 @@ -270,7 +270,7 @@ func main() {
},
}

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