Skip to content

Commit 5950285

Browse files
committed
connector: Connectors without a RefreshConnector should not return a refresh token instead of erroring
1 parent b112aa2 commit 5950285

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

connector/oidc/oidc.go

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (c *Config) Open(logger logrus.FieldLogger) (conn connector.Connector, err
117117

118118
var (
119119
_ connector.CallbackConnector = (*oidcConnector)(nil)
120+
_ connector.RefreshConnector = (*oidcConnector)(nil)
120121
)
121122

122123
type oidcConnector struct {
@@ -188,3 +189,8 @@ func (c *oidcConnector) HandleCallback(s connector.Scopes, r *http.Request) (ide
188189
}
189190
return identity, nil
190191
}
192+
193+
// Refresh is implemented for backwards compatibility, even though it's a no-op.
194+
func (c *oidcConnector) Refresh(ctx context.Context, s connector.Scopes, identity connector.Identity) (connector.Identity, error) {
195+
return identity, nil
196+
}

connector/saml/saml.go

-6
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ type provider struct {
241241

242242
func (p *provider) POSTData(s connector.Scopes, id string) (action, value string, err error) {
243243

244-
// NOTE(ericchiang): If we can't follow up with the identity provider, can we
245-
// support refresh tokens?
246-
if s.OfflineAccess {
247-
return "", "", fmt.Errorf("SAML does not support offline access")
248-
}
249-
250244
r := &authnRequest{
251245
ProtocolBinding: bindingPOST,
252246
ID: id,

server/handlers.go

+14
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,20 @@ func (s *Server) handleAuthCode(w http.ResponseWriter, r *http.Request, client s
646646
}
647647

648648
reqRefresh := func() bool {
649+
// Ensure the connector supports refresh tokens.
650+
//
651+
// Connectors like `samlExperimental` do not implement RefreshConnector.
652+
conn, ok := s.connectors[authCode.ConnectorID]
653+
if !ok {
654+
s.logger.Errorf("connector ID not found: %q", authCode.ConnectorID)
655+
s.tokenErrHelper(w, errServerError, "", http.StatusInternalServerError)
656+
return false
657+
}
658+
_, ok = conn.Connector.(connector.RefreshConnector)
659+
if !ok {
660+
return false
661+
}
662+
649663
for _, scope := range authCode.Scopes {
650664
if scope == scopeOfflineAccess {
651665
return true

0 commit comments

Comments
 (0)