Skip to content

Commit

Permalink
fix: create openid session when log in succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas committed Nov 18, 2024
1 parent 7f76c0a commit b3e1342
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 deletions.
2 changes: 1 addition & 1 deletion oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ func (h *Handler) performOAuth2DeviceVerificationFlow(w http.ResponseWriter, r *

// Update the OpenID Connect session if "openid" scope is granted
if req.GetGrantedScopes().Has("openid") {
err = h.r.OAuth2Storage().UpdateOpenIDConnectSessionByRequestID(ctx, f.DeviceCodeRequestID.String(), req)
err = h.r.OAuth2Storage().CreateOpenIDConnectSession(ctx, req.GetID(), req)
if err != nil {
x.LogError(r, err, h.r.Logger())
h.r.Writer().WriteError(w, r, err)
Expand Down
24 changes: 0 additions & 24 deletions persistence/sql/persister_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,30 +499,6 @@ func (p *Persister) CreateOpenIDConnectSession(ctx context.Context, signature st
return p.createSession(ctx, signature, requester, sqlTableOpenID, requester.GetSession().GetExpiresAt(fosite.AuthorizeCode).UTC())
}

// UpdateOpenIDConnectSessionByRequestID updates an OpenID session by requestID
func (p *Persister) UpdateOpenIDConnectSessionByRequestID(ctx context.Context, requestID string, requester fosite.Requester) (err error) {
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.UpdateOpenIDConnectSessionByRequestID")
defer otelx.End(span, &err)

req, err := p.sqlSchemaFromRequest(ctx, requestID, requester, sqlTableOpenID, requester.GetSession().GetExpiresAt(fosite.IDToken).UTC())
if err != nil {
return err
}

stmt := fmt.Sprintf(
"UPDATE %s SET granted_scope=?, granted_audience=?, session_data=? WHERE request_id=? AND nid = ?",
OAuth2RequestSQL{Table: sqlTableOpenID}.TableName(),
)

/* #nosec G201 table is static */
err = p.Connection(ctx).RawQuery(stmt, req.GrantedScope, req.GrantedAudience, req.Session, requestID, p.NetworkID(ctx)).Exec()
if err != nil {
return sqlcon.HandleError(err)
}

return nil
}

func (p *Persister) GetOpenIDConnectSession(ctx context.Context, signature string, requester fosite.Requester) (_ fosite.Requester, err error) {
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.GetOpenIDConnectSession")
defer otelx.End(span, &err)
Expand Down
2 changes: 0 additions & 2 deletions x/fosite_storer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ type FositeStorer interface {

FlushInactiveRefreshTokens(ctx context.Context, notAfter time.Time, limit int, batchSize int) error

UpdateOpenIDConnectSessionByRequestID(ctx context.Context, requestID string, requester fosite.Requester) error

// DeleteOpenIDConnectSession deletes an OpenID Connect session.
// This is duplicated from Ory Fosite to help against deprecation linting errors.
DeleteOpenIDConnectSession(ctx context.Context, authorizeCode string) error
Expand Down

0 comments on commit b3e1342

Please sign in to comment.