2021-02-22 12:27:47 +01:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2021-02-22 12:27:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type APIApp struct {
|
|
|
|
models.ObjectRoot
|
|
|
|
|
|
|
|
AppID string
|
|
|
|
AppName string
|
|
|
|
ClientID string
|
2024-04-05 12:35:49 +03:00
|
|
|
EncodedHash string
|
2021-02-22 12:27:47 +01: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 12:51:15 +01:00
|
|
|
return a.AppName != ""
|
2021-02-22 12:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIApp) setClientID(clientID string) {
|
|
|
|
a.ClientID = clientID
|
|
|
|
}
|
|
|
|
|
2024-04-05 12:35:49 +03:00
|
|
|
func (a *APIApp) setClientSecret(encodedHash string) {
|
|
|
|
a.EncodedHash = encodedHash
|
2021-02-22 12:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *APIApp) requiresClientSecret() bool {
|
|
|
|
return a.AuthMethodType == APIAuthMethodTypeBasic
|
|
|
|
}
|
|
|
|
|
2024-04-05 12:35:49 +03:00
|
|
|
func (a *APIApp) GenerateClientSecretIfNeeded(generator *crypto.HashGenerator) (plain string, err error) {
|
2021-02-22 12:27:47 +01:00
|
|
|
if a.AuthMethodType == APIAuthMethodTypePrivateKeyJWT {
|
|
|
|
return "", nil
|
|
|
|
}
|
2024-04-05 12:35:49 +03:00
|
|
|
a.EncodedHash, plain, err = generator.NewCode()
|
2021-02-22 12:27:47 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2024-04-05 12:35:49 +03:00
|
|
|
return plain, nil
|
2021-02-22 12:27:47 +01:00
|
|
|
}
|