2021-02-22 11:27:47 +00:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2021-02-22 11:27:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type APIApp struct {
|
|
|
|
models.ObjectRoot
|
|
|
|
|
|
|
|
AppID string
|
|
|
|
AppName string
|
|
|
|
ClientID string
|
2024-04-05 09:35:49 +00:00
|
|
|
EncodedHash string
|
2021-02-22 11:27:47 +00:00
|
|
|
ClientSecretString string
|
|
|
|
AuthMethodType APIAuthMethodType
|
|
|
|
|
|
|
|
State AppState
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIApp) GetApplicationName() string {
|
|
|
|
return a.AppName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIApp) GetState() AppState {
|
|
|
|
return a.State
|
|
|
|
}
|
|
|
|
|
|
|
|
type APIAuthMethodType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
APIAuthMethodTypeBasic APIAuthMethodType = iota
|
|
|
|
APIAuthMethodTypePrivateKeyJWT
|
|
|
|
)
|
|
|
|
|
|
|
|
func (a *APIApp) IsValid() bool {
|
2021-03-15 11:51:15 +00:00
|
|
|
return a.AppName != ""
|
2021-02-22 11:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIApp) setClientID(clientID string) {
|
|
|
|
a.ClientID = clientID
|
|
|
|
}
|
|
|
|
|
2024-04-05 09:35:49 +00:00
|
|
|
func (a *APIApp) setClientSecret(encodedHash string) {
|
|
|
|
a.EncodedHash = encodedHash
|
2021-02-22 11:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIApp) requiresClientSecret() bool {
|
|
|
|
return a.AuthMethodType == APIAuthMethodTypeBasic
|
|
|
|
}
|
|
|
|
|
2024-04-05 09:35:49 +00:00
|
|
|
func (a *APIApp) GenerateClientSecretIfNeeded(generator *crypto.HashGenerator) (plain string, err error) {
|
2021-02-22 11:27:47 +00:00
|
|
|
if a.AuthMethodType == APIAuthMethodTypePrivateKeyJWT {
|
|
|
|
return "", nil
|
|
|
|
}
|
2024-04-05 09:35:49 +00:00
|
|
|
a.EncodedHash, plain, err = generator.NewCode()
|
2021-02-22 11:27:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2024-04-05 09:35:49 +00:00
|
|
|
return plain, nil
|
2021-02-22 11:27:47 +00:00
|
|
|
}
|