mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-30 10:56:28 +02:00
singleflight incoming idp token session creation (#5491)
This commit is contained in:
parent
4b95eda51e
commit
f15400493d
1 changed files with 75 additions and 61 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"golang.org/x/sync/singleflight"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/internal/encoding"
|
"github.com/pomerium/pomerium/internal/encoding"
|
||||||
|
@ -138,6 +139,7 @@ type incomingIDPTokenSessionCreator struct {
|
||||||
timeNow func() time.Time
|
timeNow func() time.Time
|
||||||
getRecord func(ctx context.Context, recordType, recordID string) (*databroker.Record, error)
|
getRecord func(ctx context.Context, recordType, recordID string) (*databroker.Record, error)
|
||||||
putRecords func(ctx context.Context, records []*databroker.Record) error
|
putRecords func(ctx context.Context, records []*databroker.Record) error
|
||||||
|
singleflight singleflight.Group
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIncomingIDPTokenSessionCreator(
|
func NewIncomingIDPTokenSessionCreator(
|
||||||
|
@ -179,6 +181,7 @@ func (c *incomingIDPTokenSessionCreator) createSessionAccessToken(
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionID := getAccessTokenSessionID(idp, rawAccessToken)
|
sessionID := getAccessTokenSessionID(idp, rawAccessToken)
|
||||||
|
res, err, _ := c.singleflight.Do(sessionID, func() (any, error) {
|
||||||
s, err := c.getSession(ctx, sessionID)
|
s, err := c.getSession(ctx, sessionID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return s, nil
|
return s, nil
|
||||||
|
@ -214,6 +217,11 @@ func (c *incomingIDPTokenSessionCreator) createSessionAccessToken(
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return res.(*session.Session), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *incomingIDPTokenSessionCreator) createSessionForIdentityToken(
|
func (c *incomingIDPTokenSessionCreator) createSessionForIdentityToken(
|
||||||
|
@ -228,6 +236,7 @@ func (c *incomingIDPTokenSessionCreator) createSessionForIdentityToken(
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionID := getIdentityTokenSessionID(idp, rawIdentityToken)
|
sessionID := getIdentityTokenSessionID(idp, rawIdentityToken)
|
||||||
|
res, err, _ := c.singleflight.Do(sessionID, func() (any, error) {
|
||||||
s, err := c.getSession(ctx, sessionID)
|
s, err := c.getSession(ctx, sessionID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return s, nil
|
return s, nil
|
||||||
|
@ -259,6 +268,11 @@ func (c *incomingIDPTokenSessionCreator) createSessionForIdentityToken(
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return res.(*session.Session), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *incomingIDPTokenSessionCreator) newSessionFromIDPClaims(
|
func (c *incomingIDPTokenSessionCreator) newSessionFromIDPClaims(
|
||||||
|
|
Loading…
Add table
Reference in a new issue