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)
| 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. |
| 105 | func (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. |
no test coverage detected