Skip to content

Commit

Permalink
feat: helper/convenience finish login function for discoverable funct…
Browse files Browse the repository at this point in the history
…ions (#173)

This implements a FinishLogin equivalent function for the discoverable login functions. This is a convenience wrapper around other parts of machinery which can be individually used like it's counterpart. 

Closes #172
  • Loading branch information
boris-lenzinger authored Oct 23, 2023
1 parent feda47a commit 9cc24fa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions webauthn/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ func (webauthn *WebAuthn) FinishLogin(user User, session SessionData, response *
return webauthn.ValidateLogin(user, session, parsedResponse)
}

// FinishDiscoverableLogin takes the response from the client and validate it against the handler and stored session data.
// The handler helps to find out which user must be used to validate the response. This is a function defined in your
// business code that will retrieve the user from your persistent data.
func (webauthn *WebAuthn) FinishDiscoverableLogin(handler DiscoverableUserHandler, session SessionData, response *http.Request) (*Credential, error) {
parsedResponse, err := protocol.ParseCredentialRequestResponse(response)
if err != nil {
return nil, err
}

return webauthn.ValidateDiscoverableLogin(handler, session, parsedResponse)
}

// ValidateLogin takes a parsed response and validates it against the user credentials and session data.
func (webauthn *WebAuthn) ValidateLogin(user User, session SessionData, parsedResponse *protocol.ParsedCredentialAssertionData) (*Credential, error) {
if !bytes.Equal(user.WebAuthnID(), session.UserID) {
Expand Down

0 comments on commit 9cc24fa

Please sign in to comment.