2021-02-22 12:27:47 +01:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"time"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2021-02-22 12:27:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type ApplicationKey struct {
|
|
|
|
models.ObjectRoot
|
|
|
|
|
|
|
|
ApplicationID string
|
|
|
|
ClientID string
|
|
|
|
KeyID string
|
|
|
|
Type AuthNKeyType
|
|
|
|
ExpirationDate time.Time
|
|
|
|
PrivateKey []byte
|
|
|
|
PublicKey []byte
|
|
|
|
}
|
|
|
|
|
2022-12-09 13:04:33 +00:00
|
|
|
func (k *ApplicationKey) SetPublicKey(publicKey []byte) {
|
2021-02-22 12:27:47 +01:00
|
|
|
k.PublicKey = publicKey
|
|
|
|
}
|
|
|
|
|
2022-12-09 13:04:33 +00:00
|
|
|
func (k *ApplicationKey) SetPrivateKey(privateKey []byte) {
|
2021-02-22 12:27:47 +01:00
|
|
|
k.PrivateKey = privateKey
|
|
|
|
}
|
|
|
|
|
2022-12-09 13:04:33 +00:00
|
|
|
func (k *ApplicationKey) GetExpirationDate() time.Time {
|
2021-02-22 12:27:47 +01:00
|
|
|
return k.ExpirationDate
|
|
|
|
}
|
|
|
|
|
2022-12-09 13:04:33 +00:00
|
|
|
func (k *ApplicationKey) SetExpirationDate(expiration time.Time) {
|
2021-02-22 12:27:47 +01:00
|
|
|
k.ExpirationDate = expiration
|
|
|
|
}
|
|
|
|
|
|
|
|
func (k *ApplicationKey) Detail() ([]byte, error) {
|
|
|
|
if k.Type == AuthNKeyTypeJSON {
|
|
|
|
return k.MarshalJSON()
|
|
|
|
}
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "KEY-dsg52", "Errors.Internal")
|
2021-02-22 12:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (k *ApplicationKey) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
KeyID string `json:"keyId"`
|
|
|
|
Key string `json:"key"`
|
|
|
|
AppID string `json:"appId"`
|
2021-05-20 15:47:22 +02:00
|
|
|
ClientID string `json:"clientId"`
|
2021-02-22 12:27:47 +01:00
|
|
|
}{
|
|
|
|
Type: "application",
|
|
|
|
KeyID: k.KeyID,
|
|
|
|
Key: string(k.PrivateKey),
|
|
|
|
AppID: k.ApplicationID,
|
|
|
|
ClientID: k.ClientID,
|
|
|
|
})
|
|
|
|
}
|