mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-04 18:08:50 +00:00
feat: get/list Zitadel IdP (#12394)
# Which Problems Are Solved This PR extends the functionality of `GetProviderByID`, `ListProviders` v1 endpoints and `GetIDPByID` v2 endpoint to also return Zitadel IdP when queried. # How the Problems Are Solved - Add `PROVIDER_TYPE_ZITADEL` and a `ZitadelConfig` to `zitadel.idp.v1.ProviderConfig` (v1 APIs). - Add `IDP_TYPE_ZITADEL`, `ZitadelConfig`, `InstanceRolesInfo` in v2 `idp.proto` - Extend internal/query IDP template querying to include a `ZitadelIDPTemplate` (incl. issuer, client credentials, scopes, instance roles info). - Add/extend integration tests for updating + fetching providers by ID and listing providers. # Additional Changes N/A # Additional Context Closes https://github.com/zitadel/zitadel/issues/12051 --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
39ad66bded
commit
77169181a3
@@ -47,6 +47,7 @@ type IDPTemplate struct {
|
||||
*LDAPIDPTemplate
|
||||
*AppleIDPTemplate
|
||||
*SAMLIDPTemplate
|
||||
*ZitadelIDPTemplate
|
||||
}
|
||||
|
||||
type IDPTemplates struct {
|
||||
@@ -170,6 +171,15 @@ type SAMLIDPTemplate struct {
|
||||
FederatedLogoutEnabled bool
|
||||
}
|
||||
|
||||
type ZitadelIDPTemplate struct {
|
||||
IDPID string
|
||||
ClientID string
|
||||
ClientSecret *crypto.CryptoValue
|
||||
Issuer string
|
||||
Scopes database.TextArray[string]
|
||||
InstanceRolesInfo database.JSONArray[idp.RolesInfo]
|
||||
}
|
||||
|
||||
var (
|
||||
idpTemplateTable = table{
|
||||
name: projection.IDPTemplateTable,
|
||||
@@ -741,6 +751,41 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
zitadelIdpTemplateTable = table{
|
||||
name: projection.IDPTemplateZitadelTable,
|
||||
instanceIDCol: projection.ZitadelInstanceIDCol,
|
||||
}
|
||||
ZitadelIDCol = Column{
|
||||
name: projection.ZitadelIDCol,
|
||||
table: zitadelIdpTemplateTable,
|
||||
}
|
||||
ZitadelInstanceIDCol = Column{
|
||||
name: projection.ZitadelInstanceIDCol,
|
||||
table: zitadelIdpTemplateTable,
|
||||
}
|
||||
ZitadelIssuerCol = Column{
|
||||
name: projection.ZitadelIssuerCol,
|
||||
table: zitadelIdpTemplateTable,
|
||||
}
|
||||
ZitadelClientIDCol = Column{
|
||||
name: projection.ZitadelClientIDCol,
|
||||
table: zitadelIdpTemplateTable,
|
||||
}
|
||||
ZitadelClientSecretCol = Column{
|
||||
name: projection.ZitadelClientSecretCol,
|
||||
table: zitadelIdpTemplateTable,
|
||||
}
|
||||
ZitadelScopesCol = Column{
|
||||
name: projection.ZitadelScopesCol,
|
||||
table: zitadelIdpTemplateTable,
|
||||
}
|
||||
ZitadelInstanceRolesInfoCol = Column{
|
||||
name: projection.ZitadelInstanceRolesInfoCol,
|
||||
table: zitadelIdpTemplateTable,
|
||||
}
|
||||
)
|
||||
|
||||
// IDPTemplateByID searches for the requested id with permission check if necessary
|
||||
func (q *Queries) IDPTemplateByID(ctx context.Context, shouldTriggerBulk bool, id string, withOwnerRemoved bool, permissionCheck domain.PermissionCheck, queries ...SearchQuery) (template *IDPTemplate, err error) {
|
||||
idp, err := q.idpTemplateByID(ctx, shouldTriggerBulk, id, withOwnerRemoved, queries...)
|
||||
@@ -998,6 +1043,13 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
AppleKeyIDCol.identifier(),
|
||||
ApplePrivateKeyCol.identifier(),
|
||||
AppleScopesCol.identifier(),
|
||||
// zitadel
|
||||
ZitadelIDCol.identifier(),
|
||||
ZitadelIssuerCol.identifier(),
|
||||
ZitadelClientIDCol.identifier(),
|
||||
ZitadelClientSecretCol.identifier(),
|
||||
ZitadelScopesCol.identifier(),
|
||||
ZitadelInstanceRolesInfoCol.identifier(),
|
||||
).From(idpTemplateTable.identifier()).
|
||||
LeftJoin(join(OAuthIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(OIDCIDCol, IDPTemplateIDCol)).
|
||||
@@ -1011,6 +1063,7 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
LeftJoin(join(SAMLIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(LDAPIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(AppleIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(ZitadelIDCol, IDPTemplateIDCol)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
func(row *sql.Row) (*IDPTemplate, error) {
|
||||
idpTemplate := new(IDPTemplate)
|
||||
@@ -1121,6 +1174,13 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
applePrivateKey := new(crypto.CryptoValue)
|
||||
appleScopes := database.TextArray[string]{}
|
||||
|
||||
zitadelID := sql.NullString{}
|
||||
zitadelClientID := sql.NullString{}
|
||||
zitadelClientSecret := new(crypto.CryptoValue)
|
||||
zitadelIssuer := sql.NullString{}
|
||||
zitadelScopes := database.TextArray[string]{}
|
||||
zitadelInstanceRolesInfo := database.JSONArray[idp.RolesInfo]{}
|
||||
|
||||
err := row.Scan(
|
||||
&idpTemplate.ID,
|
||||
&idpTemplate.ResourceOwner,
|
||||
@@ -1240,6 +1300,13 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
&appleKeyID,
|
||||
&applePrivateKey,
|
||||
&appleScopes,
|
||||
// zitadel
|
||||
&zitadelID,
|
||||
&zitadelIssuer,
|
||||
&zitadelClientID,
|
||||
&zitadelClientSecret,
|
||||
&zitadelScopes,
|
||||
&zitadelInstanceRolesInfo,
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -1392,7 +1459,16 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
Scopes: appleScopes,
|
||||
}
|
||||
}
|
||||
|
||||
if zitadelID.Valid {
|
||||
idpTemplate.ZitadelIDPTemplate = &ZitadelIDPTemplate{
|
||||
IDPID: zitadelID.String,
|
||||
ClientID: zitadelClientID.String,
|
||||
ClientSecret: zitadelClientSecret,
|
||||
Issuer: zitadelIssuer.String,
|
||||
Scopes: zitadelScopes,
|
||||
InstanceRolesInfo: zitadelInstanceRolesInfo,
|
||||
}
|
||||
}
|
||||
return idpTemplate, nil
|
||||
}
|
||||
}
|
||||
@@ -1518,6 +1594,13 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
AppleKeyIDCol.identifier(),
|
||||
ApplePrivateKeyCol.identifier(),
|
||||
AppleScopesCol.identifier(),
|
||||
// zitadel
|
||||
ZitadelIDCol.identifier(),
|
||||
ZitadelIssuerCol.identifier(),
|
||||
ZitadelClientIDCol.identifier(),
|
||||
ZitadelClientSecretCol.identifier(),
|
||||
ZitadelScopesCol.identifier(),
|
||||
ZitadelInstanceRolesInfoCol.identifier(),
|
||||
// count
|
||||
countColumn.identifier(),
|
||||
).From(idpTemplateTable.identifier()).
|
||||
@@ -1533,6 +1616,7 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
LeftJoin(join(SAMLIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(LDAPIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(AppleIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(ZitadelIDCol, IDPTemplateIDCol)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
func(rows *sql.Rows) (*IDPTemplates, error) {
|
||||
templates := make([]*IDPTemplate, 0)
|
||||
@@ -1646,6 +1730,13 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
applePrivateKey := new(crypto.CryptoValue)
|
||||
appleScopes := database.TextArray[string]{}
|
||||
|
||||
zitadelID := sql.NullString{}
|
||||
zitadelIssuer := sql.NullString{}
|
||||
zitadelClientID := sql.NullString{}
|
||||
zitadelClientSecret := new(crypto.CryptoValue)
|
||||
zitadelScopes := database.TextArray[string]{}
|
||||
zitadelInstanceRolesInfo := database.JSONArray[idp.RolesInfo]{}
|
||||
|
||||
err := rows.Scan(
|
||||
&idpTemplate.ID,
|
||||
&idpTemplate.ResourceOwner,
|
||||
@@ -1765,6 +1856,13 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
&appleKeyID,
|
||||
&applePrivateKey,
|
||||
&appleScopes,
|
||||
// zitadel
|
||||
&zitadelID,
|
||||
&zitadelIssuer,
|
||||
&zitadelClientID,
|
||||
&zitadelClientSecret,
|
||||
&zitadelScopes,
|
||||
&zitadelInstanceRolesInfo,
|
||||
&count,
|
||||
)
|
||||
|
||||
@@ -1916,6 +2014,16 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
Scopes: appleScopes,
|
||||
}
|
||||
}
|
||||
if zitadelID.Valid {
|
||||
idpTemplate.ZitadelIDPTemplate = &ZitadelIDPTemplate{
|
||||
IDPID: zitadelID.String,
|
||||
Issuer: zitadelIssuer.String,
|
||||
ClientID: zitadelClientID.String,
|
||||
ClientSecret: zitadelClientSecret,
|
||||
Scopes: zitadelScopes,
|
||||
InstanceRolesInfo: zitadelInstanceRolesInfo,
|
||||
}
|
||||
}
|
||||
templates = append(templates, idpTemplate)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user