fix: allow setting client/secret id for a new backend
This commit is contained in:
parent
c9f89f496f
commit
296909ef1f
1 changed files with 19 additions and 12 deletions
|
@ -4,15 +4,17 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/cmd/utils"
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/cmd/utils"
|
||||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/services"
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/logger"
|
||||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/services/backend"
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/services/backend"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
backendID string
|
backendID string
|
||||||
backendName string
|
backendName string
|
||||||
backendIssuer string
|
backendIssuer string
|
||||||
|
backendClientID string
|
||||||
|
backendClientSecret string
|
||||||
)
|
)
|
||||||
|
|
||||||
var backendAddCmd = &cobra.Command{
|
var backendAddCmd = &cobra.Command{
|
||||||
|
@ -25,7 +27,9 @@ Parameters to provide:
|
||||||
- name: Human readable name to represent the backend. It will be used by
|
- name: Human readable name to represent the backend. It will be used by
|
||||||
the user in the authentication page to select a backend during
|
the user in the authentication page to select a backend during
|
||||||
authentication
|
authentication
|
||||||
- issuer: Full hostname of the OIDC provider, e.g. 'https://github.com'`,
|
- issuer: Full hostname of the OIDC provider, e.g. 'https://github.com'
|
||||||
|
- client-id: OIDC Client ID for the backend
|
||||||
|
- client-secret OIDC Client secret for the backend`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
addNewBackend()
|
addNewBackend()
|
||||||
},
|
},
|
||||||
|
@ -33,17 +37,20 @@ Parameters to provide:
|
||||||
|
|
||||||
func addNewBackend() {
|
func addNewBackend() {
|
||||||
c := utils.InitConfig("")
|
c := utils.InitConfig("")
|
||||||
|
logger.Init(c.LogLevel)
|
||||||
s := utils.InitStorage(c)
|
s := utils.InitStorage(c)
|
||||||
|
|
||||||
clientID, clientSecret, err := services.GenerateClientIDSecret()
|
if backendClientID == "" {
|
||||||
if err != nil {
|
utils.Fail("Empty client ID")
|
||||||
utils.Failf("Failed to generate client id or secret: %s", err.Error())
|
}
|
||||||
|
if backendClientSecret == "" {
|
||||||
|
utils.Fail("Empty client secret")
|
||||||
}
|
}
|
||||||
|
|
||||||
backendConf := backend.BackendConfig{
|
backendConf := backend.BackendConfig{
|
||||||
Issuer: backendIssuer,
|
Issuer: backendIssuer,
|
||||||
ClientID: clientID,
|
ClientID: backendClientID,
|
||||||
ClientSecret: clientSecret,
|
ClientSecret: backendClientSecret,
|
||||||
RedirectURI: c.RedirectURI(),
|
RedirectURI: c.RedirectURI(),
|
||||||
ID: backendID,
|
ID: backendID,
|
||||||
Name: backendName,
|
Name: backendName,
|
||||||
|
@ -53,8 +60,6 @@ func addNewBackend() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("New backend %s added.\n", backendName)
|
fmt.Printf("New backend %s added.\n", backendName)
|
||||||
printProperty("Client ID", clientID)
|
|
||||||
printProperty("Client secret", clientSecret)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -63,4 +68,6 @@ func init() {
|
||||||
backendAddCmd.Flags().StringVarP(&backendID, "id", "i", "", "ID to identify the backend in the storage")
|
backendAddCmd.Flags().StringVarP(&backendID, "id", "i", "", "ID to identify the backend in the storage")
|
||||||
backendAddCmd.Flags().StringVarP(&backendName, "name", "n", "", "Name to represent the backend")
|
backendAddCmd.Flags().StringVarP(&backendName, "name", "n", "", "Name to represent the backend")
|
||||||
backendAddCmd.Flags().StringVarP(&backendIssuer, "issuer", "d", "", "Full hostname of the backend")
|
backendAddCmd.Flags().StringVarP(&backendIssuer, "issuer", "d", "", "Full hostname of the backend")
|
||||||
|
backendAddCmd.Flags().StringVarP(&backendClientID, "client-id", "", "", "OIDC Client ID for the backend")
|
||||||
|
backendAddCmd.Flags().StringVarP(&backendClientSecret, "client-secret", "", "", "OIDC Client secret for the backend")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue