MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / deleteOneTimeSession

Method deleteOneTimeSession

auth/session.go:105–120  ·  view source on GitHub ↗

deleteOneTimeSession deletes the session if it is marked as a one-time session. If the session can be not deleted, or was already deleted an error is returned.

(ctx context.Context, session *LoginSession)

Source from the content-addressed store, hash-verified

103// deleteOneTimeSession deletes the session if it is marked as a one-time session. If the session can be not deleted, or
104// was already deleted an error is returned.
105func (auth *Authenticator) deleteOneTimeSession(ctx context.Context, session *LoginSession) error {
106 if session.OneTime == nil || !*session.OneTime {
107 return nil
108 }
109 err := auth.datastore.Delete(auth.DocIDForSession(session.ID))
110 if err != nil {
111 // If doc is not found, it probably means someone else is simultaneously using the one-time session, error.
112 // If the delete error comes from another source, still treat this as an error, expecting the client to retry
113 // due to a temporary KV issue.
114 if !base.IsDocNotFoundError(err) {
115 base.InfofCtx(ctx, base.KeyAuth, "Unable to delete one-time session %s. Not allowing login: %v", base.UD(session.ID), err)
116 }
117 return base.HTTPErrorf(http.StatusUnauthorized, "Session Invalid")
118 }
119 return nil
120}
121
122// CreateSession creates a new login session for the specified user with the specified TTL. If oneTime is true, the
123// session is marked as a one-time session and will be removed with a successful authentication.

Callers 2

AuthenticateCookieMethod · 0.95

Calls 6

DocIDForSessionMethod · 0.95
IsDocNotFoundErrorFunction · 0.92
InfofCtxFunction · 0.92
UDFunction · 0.92
HTTPErrorfFunction · 0.92
DeleteMethod · 0.45

Tested by

no test coverage detected