@@ -31,6 +31,16 @@ type DiscoverableUserHandler func(rawID, userHandle []byte) (user User, err erro
3131//
3232// Specification: §5.5. Options for Assertion Generation (https://www.w3.org/TR/webauthn/#dictionary-assertion-options)
3333func (webauthn * WebAuthn ) BeginLogin (user User , opts ... LoginOption ) (* protocol.CredentialAssertion , * SessionData , error ) {
34+ return webauthn .BeginMediatedLogin (user , "" , opts ... )
35+ }
36+
37+ // BeginDiscoverableLogin begins a client-side discoverable login, previously known as Resident Key logins.
38+ func (webauthn * WebAuthn ) BeginDiscoverableLogin (opts ... LoginOption ) (* protocol.CredentialAssertion , * SessionData , error ) {
39+ return webauthn .beginLogin (nil , nil , "" , opts ... )
40+ }
41+
42+ // BeginMediatedLogin is similar to BeginLogin however it also allows specifying a credential mediation requirement.
43+ func (webauthn * WebAuthn ) BeginMediatedLogin (user User , mediation protocol.CredentialMediationRequirement , opts ... LoginOption ) (* protocol.CredentialAssertion , * SessionData , error ) {
3444 credentials := user .WebAuthnCredentials ()
3545
3646 if len (credentials ) == 0 { // If the user does not have any credentials, we cannot perform an assertion.
@@ -43,15 +53,16 @@ func (webauthn *WebAuthn) BeginLogin(user User, opts ...LoginOption) (*protocol.
4353 allowedCredentials [i ] = credential .Descriptor ()
4454 }
4555
46- return webauthn .beginLogin (user .WebAuthnID (), allowedCredentials , opts ... )
56+ return webauthn .beginLogin (user .WebAuthnID (), allowedCredentials , mediation , opts ... )
4757}
4858
49- // BeginDiscoverableLogin begins a client-side discoverable login, previously known as Resident Key logins.
50- func (webauthn * WebAuthn ) BeginDiscoverableLogin (opts ... LoginOption ) (* protocol.CredentialAssertion , * SessionData , error ) {
51- return webauthn .beginLogin (nil , nil , opts ... )
59+ // BeginDiscoverableMediatedLogin begins a client-side discoverable login with a mediation requirement, previously known
60+ // as Resident Key logins.
61+ func (webauthn * WebAuthn ) BeginDiscoverableMediatedLogin (mediation protocol.CredentialMediationRequirement , opts ... LoginOption ) (* protocol.CredentialAssertion , * SessionData , error ) {
62+ return webauthn .beginLogin (nil , nil , mediation , opts ... )
5263}
5364
54- func (webauthn * WebAuthn ) beginLogin (userID []byte , allowedCredentials []protocol.CredentialDescriptor , opts ... LoginOption ) (assertion * protocol.CredentialAssertion , session * SessionData , err error ) {
65+ func (webauthn * WebAuthn ) beginLogin (userID []byte , allowedCredentials []protocol.CredentialDescriptor , mediation protocol. CredentialMediationRequirement , opts ... LoginOption ) (assertion * protocol.CredentialAssertion , session * SessionData , err error ) {
5566 if err = webauthn .Config .validate (); err != nil {
5667 return nil , nil , fmt .Errorf (errFmtConfigValidate , err )
5768 }
@@ -62,6 +73,7 @@ func (webauthn *WebAuthn) beginLogin(userID []byte, allowedCredentials []protoco
6273 UserVerification : webauthn .Config .AuthenticatorSelection .UserVerification ,
6374 AllowedCredentials : allowedCredentials ,
6475 },
76+ Mediation : mediation ,
6577 }
6678
6779 for _ , opt := range opts {
0 commit comments