feat: add apis and application keys (#1327)

* feat: add apis and application keys

* VerifyOIDCClientSecret

* Update internal/v2/repository/project/api_config.go

Co-authored-by: Fabi <[email protected]>

* Update internal/v2/repository/project/key.go

Co-authored-by: Fabi <[email protected]>

* fix append ApplicationKeyWriteModel

Co-authored-by: Fabi <[email protected]>
This commit is contained in:
Livio Amstutz
2021-02-22 12:27:47 +01:00
committed by GitHub
co-authored by Fabi
parent a7cc57822b
commit 2ba56595b1
35 changed files with 1421 additions and 527 deletions
+16 -26
View File
@@ -1,29 +1,36 @@
package domain
import (
"github.com/caos/zitadel/internal/crypto"
"github.com/caos/zitadel/internal/eventstore/models"
"time"
"github.com/caos/zitadel/internal/eventstore/models"
)
type MachineKey struct {
models.ObjectRoot
KeyID string
Type MachineKeyType
Type AuthNKeyType
ExpirationDate time.Time
PrivateKey []byte
PublicKey []byte
}
type MachineKeyType int32
func (key *MachineKey) setPublicKey(publicKey []byte) {
key.PublicKey = publicKey
}
const (
MachineKeyTypeNONE = iota
MachineKeyTypeJSON
func (key *MachineKey) setPrivateKey(privateKey []byte) {
key.PrivateKey = privateKey
}
keyCount
)
func (key *MachineKey) expirationDate() time.Time {
return key.ExpirationDate
}
func (key *MachineKey) setExpirationDate(expiration time.Time) {
key.ExpirationDate = expiration
}
type MachineKeyState int32
@@ -38,20 +45,3 @@ const (
func (f MachineKeyState) Valid() bool {
return f >= 0 && f < machineKeyStateCount
}
func (f MachineKeyType) Valid() bool {
return f >= 0 && f < keyCount
}
func (key *MachineKey) GenerateNewMachineKeyPair(keySize int) error {
privateKey, publicKey, err := crypto.GenerateKeyPair(keySize)
if err != nil {
return err
}
key.PublicKey, err = crypto.PublicKeyToBytes(publicKey)
if err != nil {
return err
}
key.PrivateKey = crypto.PrivateKeyToBytes(privateKey)
return nil
}