Skip to content

Commit

Permalink
Update exisiting OIDC users upon re-login.
Browse files Browse the repository at this point in the history
  • Loading branch information
russjones committed Apr 5, 2017
1 parent fde0ae4 commit fcfb883
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,25 +839,30 @@ func (a *AuthServer) createOIDCUser(connector services.OIDCConnector, ident *oid
if err != nil {
return trace.Wrap(err)
}
err = a.CreateUser(user)
if err == nil {
return trace.Wrap(err)
}
if !trace.IsAlreadyExists(err) {
return trace.Wrap(err)
}

// check if a user exists already
existingUser, err := a.GetUser(ident.Email)
if err != nil {
if !trace.IsNotFound(err) {
return trace.Wrap(err)
}
} else {
}

// check if any exisiting user is a non-oidc user, dont override their
if existingUser != nil {
connectorRef := existingUser.GetCreatedBy().Connector
if connectorRef == nil || connectorRef.Type != teleport.ConnectorOIDC || connectorRef.ID != connector.GetName() {
return trace.AlreadyExists("user %v already exists and is not OIDC user", existingUser.GetName())
return trace.AlreadyExists("user %q already exists and is not OIDC user", existingUser.GetName())
}
}
return a.UpsertUser(user)

// no non-oidc user exists, create or update the exisiting oidc user
err = a.UpsertUser(user)
if err != nil {
return trace.Wrap(err)
}

return nil
}

// claimsFromIDToken extracts claims from the ID token.
Expand Down

0 comments on commit fcfb883

Please sign in to comment.