Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing SessionIssued event for api flows #3348

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion persistence/sql/persister_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
"github.com/gobuffalo/pop/v6"
"github.com/gofrs/uuid"
"github.com/pkg/errors"
"go.opentelemetry.io/otel/trace"
"golang.org/x/sync/errgroup"

"github.com/ory/kratos/identity"
"github.com/ory/kratos/session"
"github.com/ory/kratos/x/events"
"github.com/ory/x/otelx"
"github.com/ory/x/pagination/keysetpagination"
"github.com/ory/x/sqlcon"
Expand Down Expand Up @@ -193,7 +195,11 @@ func (p *Persister) UpsertSession(ctx context.Context, s *session.Session) (err
if exists {
// This must not be eager or identities will be created / updated
// Only update session and not corresponding session device records
return sqlcon.HandleError(tx.Update(s))
if err := tx.Update(s); err != nil {
return sqlcon.HandleError(err)
}
trace.SpanFromContext(ctx).AddEvent(events.NewSessionChanged(ctx, string(s.AuthenticatorAssuranceLevel), s.ID, s.IdentityID))
return nil
}

// This must not be eager or identities will be created / updated
Expand All @@ -218,6 +224,7 @@ func (p *Persister) UpsertSession(ctx context.Context, s *session.Session) (err
}
}

trace.SpanFromContext(ctx).AddEvent(events.NewSessionIssued(ctx, string(s.AuthenticatorAssuranceLevel), s.ID, s.IdentityID))
return nil
}))
}
Expand Down
11 changes: 7 additions & 4 deletions selfservice/flow/login/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,14 @@ func (e *HookExecutor) PostLoginHook(
Info("Identity authenticated successfully and was issued an Ory Kratos Session Token.")

trace.SpanFromContext(r.Context()).AddEvent(events.NewLoginSucceeded(r.Context(), &events.LoginSucceededOpts{
SessionID: s.ID,
IdentityID: i.ID, FlowType: string(a.Type), RequestedAAL: string(a.RequestedAAL), IsRefresh: a.Refresh, Method: a.Active.String(),
SSOProvider: provider,
SessionID: s.ID,
IdentityID: i.ID,
FlowType: string(a.Type),
RequestedAAL: string(a.RequestedAAL),
IsRefresh: a.Refresh,
Method: a.Active.String(),
SSOProvider: provider,
}))

if handled, err := e.d.SessionManager().MaybeRedirectAPICodeFlow(w, r, a, s.ID, g); err != nil {
return errors.WithStack(err)
} else if handled {
Expand Down
Loading