2021-02-22 11:27:47 +00:00
|
|
|
package domain
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
2021-02-22 11:27:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type oAuthApplication interface {
|
|
|
|
setClientID(clientID string)
|
2024-04-05 09:35:49 +00:00
|
|
|
setClientSecret(encodedHash string)
|
2021-02-22 11:27:47 +00:00
|
|
|
requiresClientSecret() bool
|
|
|
|
}
|
|
|
|
|
2024-07-04 08:31:40 +00:00
|
|
|
// ClientID random_number (eg. 495894098234)
|
|
|
|
func SetNewClientID(a oAuthApplication, idGenerator id.Generator) error {
|
|
|
|
clientID, err := idGenerator.Next()
|
2021-02-22 11:27:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
a.setClientID(clientID)
|
2021-02-22 11:27:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-05 09:35:49 +00:00
|
|
|
func SetNewClientSecretIfNeeded(a oAuthApplication, generate func() (encodedHash, plain string, err error)) (string, error) {
|
2021-02-22 11:27:47 +00:00
|
|
|
if !a.requiresClientSecret() {
|
|
|
|
return "", nil
|
|
|
|
}
|
2024-04-05 09:35:49 +00:00
|
|
|
encodedHash, plain, err := generate()
|
2021-02-22 11:27:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2024-04-05 09:35:49 +00:00
|
|
|
a.setClientSecret(encodedHash)
|
|
|
|
return plain, nil
|
2021-02-22 11:27:47 +00:00
|
|
|
}
|