mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:47:33 +00:00
feat(api): add generic oauth provider template (#5260)
adds functionality to manage templates based OIDC IDPs
This commit is contained in:
@@ -33,6 +33,7 @@ type IDPTemplate struct {
|
||||
IsLinkingAllowed bool
|
||||
IsAutoCreation bool
|
||||
IsAutoUpdate bool
|
||||
*OAuthIDPTemplate
|
||||
*GoogleIDPTemplate
|
||||
*LDAPIDPTemplate
|
||||
}
|
||||
@@ -42,6 +43,16 @@ type IDPTemplates struct {
|
||||
Templates []*IDPTemplate
|
||||
}
|
||||
|
||||
type OAuthIDPTemplate struct {
|
||||
IDPID string
|
||||
ClientID string
|
||||
ClientSecret *crypto.CryptoValue
|
||||
AuthorizationEndpoint string
|
||||
TokenEndpoint string
|
||||
UserEndpoint string
|
||||
Scopes database.StringArray
|
||||
}
|
||||
|
||||
type GoogleIDPTemplate struct {
|
||||
IDPID string
|
||||
ClientID string
|
||||
@@ -129,6 +140,45 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
oauthIdpTemplateTable = table{
|
||||
name: projection.IDPTemplateOAuthTable,
|
||||
instanceIDCol: projection.OAuthInstanceIDCol,
|
||||
}
|
||||
OAuthIDCol = Column{
|
||||
name: projection.OAuthIDCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
OAuthInstanceIDCol = Column{
|
||||
name: projection.OAuthInstanceIDCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
OAuthClientIDCol = Column{
|
||||
name: projection.OAuthClientIDCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
OAuthClientSecretCol = Column{
|
||||
name: projection.OAuthClientSecretCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
OAuthAuthorizationEndpointCol = Column{
|
||||
name: projection.OAuthAuthorizationEndpointCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
OAuthTokenEndpointCol = Column{
|
||||
name: projection.OAuthTokenEndpointCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
OAuthUserEndpointCol = Column{
|
||||
name: projection.OAuthUserEndpointCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
OAuthScopesCol = Column{
|
||||
name: projection.OAuthScopesCol,
|
||||
table: oauthIdpTemplateTable,
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
googleIdpTemplateTable = table{
|
||||
name: projection.IDPTemplateGoogleTable,
|
||||
@@ -370,10 +420,20 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
IDPTemplateIsLinkingAllowedCol.identifier(),
|
||||
IDPTemplateIsAutoCreationCol.identifier(),
|
||||
IDPTemplateIsAutoUpdateCol.identifier(),
|
||||
// oauth
|
||||
OAuthIDCol.identifier(),
|
||||
OAuthClientIDCol.identifier(),
|
||||
OAuthClientSecretCol.identifier(),
|
||||
OAuthAuthorizationEndpointCol.identifier(),
|
||||
OAuthTokenEndpointCol.identifier(),
|
||||
OAuthUserEndpointCol.identifier(),
|
||||
OAuthScopesCol.identifier(),
|
||||
// google
|
||||
GoogleIDCol.identifier(),
|
||||
GoogleClientIDCol.identifier(),
|
||||
GoogleClientSecretCol.identifier(),
|
||||
GoogleScopesCol.identifier(),
|
||||
// ldap
|
||||
LDAPIDCol.identifier(),
|
||||
LDAPHostCol.identifier(),
|
||||
LDAPPortCol.identifier(),
|
||||
@@ -397,6 +457,7 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
LDAPAvatarURLAttributeCol.identifier(),
|
||||
LDAPProfileAttributeCol.identifier(),
|
||||
).From(idpTemplateTable.identifier()).
|
||||
LeftJoin(join(OAuthIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(GoogleIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(LDAPIDCol, IDPTemplateIDCol)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
@@ -405,6 +466,14 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
|
||||
name := sql.NullString{}
|
||||
|
||||
oauthID := sql.NullString{}
|
||||
oauthClientID := sql.NullString{}
|
||||
oauthClientSecret := new(crypto.CryptoValue)
|
||||
oauthAuthorizationEndpoint := sql.NullString{}
|
||||
oauthTokenEndpoint := sql.NullString{}
|
||||
oauthUserEndpoint := sql.NullString{}
|
||||
oauthScopes := database.StringArray{}
|
||||
|
||||
googleID := sql.NullString{}
|
||||
googleClientID := sql.NullString{}
|
||||
googleClientSecret := new(crypto.CryptoValue)
|
||||
@@ -447,10 +516,20 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
&idpTemplate.IsLinkingAllowed,
|
||||
&idpTemplate.IsAutoCreation,
|
||||
&idpTemplate.IsAutoUpdate,
|
||||
// oauth
|
||||
&oauthID,
|
||||
&oauthClientID,
|
||||
&oauthClientSecret,
|
||||
&oauthAuthorizationEndpoint,
|
||||
&oauthTokenEndpoint,
|
||||
&oauthUserEndpoint,
|
||||
&oauthScopes,
|
||||
// google
|
||||
&googleID,
|
||||
&googleClientID,
|
||||
&googleClientSecret,
|
||||
&googleScopes,
|
||||
// ldap
|
||||
&ldapID,
|
||||
&ldapHost,
|
||||
&ldapPort,
|
||||
@@ -483,6 +562,17 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
|
||||
idpTemplate.Name = name.String
|
||||
|
||||
if oauthID.Valid {
|
||||
idpTemplate.OAuthIDPTemplate = &OAuthIDPTemplate{
|
||||
IDPID: oauthID.String,
|
||||
ClientID: oauthClientID.String,
|
||||
ClientSecret: oauthClientSecret,
|
||||
AuthorizationEndpoint: oauthAuthorizationEndpoint.String,
|
||||
TokenEndpoint: oauthTokenEndpoint.String,
|
||||
UserEndpoint: oauthUserEndpoint.String,
|
||||
Scopes: oauthScopes,
|
||||
}
|
||||
}
|
||||
if googleID.Valid {
|
||||
idpTemplate.GoogleIDPTemplate = &GoogleIDPTemplate{
|
||||
IDPID: googleID.String,
|
||||
@@ -490,7 +580,8 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
ClientSecret: googleClientSecret,
|
||||
Scopes: googleScopes,
|
||||
}
|
||||
} else if ldapID.Valid {
|
||||
}
|
||||
if ldapID.Valid {
|
||||
idpTemplate.LDAPIDPTemplate = &LDAPIDPTemplate{
|
||||
IDPID: ldapID.String,
|
||||
Host: ldapHost.String,
|
||||
@@ -538,10 +629,20 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
IDPTemplateIsLinkingAllowedCol.identifier(),
|
||||
IDPTemplateIsAutoCreationCol.identifier(),
|
||||
IDPTemplateIsAutoUpdateCol.identifier(),
|
||||
// oauth
|
||||
OAuthIDCol.identifier(),
|
||||
OAuthClientIDCol.identifier(),
|
||||
OAuthClientSecretCol.identifier(),
|
||||
OAuthAuthorizationEndpointCol.identifier(),
|
||||
OAuthTokenEndpointCol.identifier(),
|
||||
OAuthUserEndpointCol.identifier(),
|
||||
OAuthScopesCol.identifier(),
|
||||
// google
|
||||
GoogleIDCol.identifier(),
|
||||
GoogleClientIDCol.identifier(),
|
||||
GoogleClientSecretCol.identifier(),
|
||||
GoogleScopesCol.identifier(),
|
||||
// ldap
|
||||
LDAPIDCol.identifier(),
|
||||
LDAPHostCol.identifier(),
|
||||
LDAPPortCol.identifier(),
|
||||
@@ -566,6 +667,7 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
LDAPProfileAttributeCol.identifier(),
|
||||
countColumn.identifier(),
|
||||
).From(idpTemplateTable.identifier()).
|
||||
LeftJoin(join(OAuthIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(GoogleIDCol, IDPTemplateIDCol)).
|
||||
LeftJoin(join(LDAPIDCol, IDPTemplateIDCol)).
|
||||
PlaceholderFormat(sq.Dollar),
|
||||
@@ -577,6 +679,14 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
|
||||
name := sql.NullString{}
|
||||
|
||||
oauthID := sql.NullString{}
|
||||
oauthClientID := sql.NullString{}
|
||||
oauthClientSecret := new(crypto.CryptoValue)
|
||||
oauthAuthorizationEndpoint := sql.NullString{}
|
||||
oauthTokenEndpoint := sql.NullString{}
|
||||
oauthUserEndpoint := sql.NullString{}
|
||||
oauthScopes := database.StringArray{}
|
||||
|
||||
googleID := sql.NullString{}
|
||||
googleClientID := sql.NullString{}
|
||||
googleClientSecret := new(crypto.CryptoValue)
|
||||
@@ -619,10 +729,20 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
&idpTemplate.IsLinkingAllowed,
|
||||
&idpTemplate.IsAutoCreation,
|
||||
&idpTemplate.IsAutoUpdate,
|
||||
// oauth
|
||||
&oauthID,
|
||||
&oauthClientID,
|
||||
&oauthClientSecret,
|
||||
&oauthAuthorizationEndpoint,
|
||||
&oauthTokenEndpoint,
|
||||
&oauthUserEndpoint,
|
||||
&oauthScopes,
|
||||
// google
|
||||
&googleID,
|
||||
&googleClientID,
|
||||
&googleClientSecret,
|
||||
&googleScopes,
|
||||
// ldap
|
||||
&ldapID,
|
||||
&ldapHost,
|
||||
&ldapPort,
|
||||
@@ -654,6 +774,17 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
|
||||
idpTemplate.Name = name.String
|
||||
|
||||
if oauthID.Valid {
|
||||
idpTemplate.OAuthIDPTemplate = &OAuthIDPTemplate{
|
||||
IDPID: oauthID.String,
|
||||
ClientID: oauthClientID.String,
|
||||
ClientSecret: oauthClientSecret,
|
||||
AuthorizationEndpoint: oauthAuthorizationEndpoint.String,
|
||||
TokenEndpoint: oauthTokenEndpoint.String,
|
||||
UserEndpoint: oauthUserEndpoint.String,
|
||||
Scopes: oauthScopes,
|
||||
}
|
||||
}
|
||||
if googleID.Valid {
|
||||
idpTemplate.GoogleIDPTemplate = &GoogleIDPTemplate{
|
||||
IDPID: googleID.String,
|
||||
@@ -661,7 +792,8 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
ClientSecret: googleClientSecret,
|
||||
Scopes: googleScopes,
|
||||
}
|
||||
} else if ldapID.Valid {
|
||||
}
|
||||
if ldapID.Valid {
|
||||
idpTemplate.LDAPIDPTemplate = &LDAPIDPTemplate{
|
||||
IDPID: ldapID.String,
|
||||
Host: ldapHost.String,
|
||||
|
Reference in New Issue
Block a user