Skip to content

Commit

Permalink
Implementation of #172
Browse files Browse the repository at this point in the history
The required elements were already in the code. Was missing this simple
function to get methods to finish login in both cases (discoverable
credentials or not discoverable).
  • Loading branch information
boris-lenzinger committed Oct 23, 2023
1 parent feda47a commit 89cc04b
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 89cc04b

Please sign in to comment.