mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-04-07 22:37:55 +00:00
feat: oidc client create command (#672)
* feat: add oidc client create command * refactor: use own utility for creating random strings (more flexible than stdlib) * feat: validate client name to avoid config errors * refactor: limit to only alphanumeric characters and hyphens * refactor: remove the need of the logger in the create oidc client cmd
This commit is contained in:
43
cmd/tinyauth/create_oidc_client.go
Normal file
43
cmd/tinyauth/create_oidc_client.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/steveiliop56/tinyauth/internal/utils"
|
||||
"github.com/traefik/paerser/cli"
|
||||
)
|
||||
|
||||
func createOidcClientCmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "create",
|
||||
Description: "Create a new OIDC Client",
|
||||
Configuration: nil,
|
||||
Resources: nil,
|
||||
AllowArg: true,
|
||||
Run: func(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("client name is required. use tinyauth oidc create <name>")
|
||||
}
|
||||
|
||||
clientName := args[0]
|
||||
|
||||
match, err := regexp.MatchString("^[a-zA-Z0-9-]*$", clientName)
|
||||
|
||||
if !match || err != nil {
|
||||
return errors.New("client name can only contain alphanumeric characters and hyphens")
|
||||
}
|
||||
|
||||
uuid := uuid.New()
|
||||
clientId := uuid.String()
|
||||
clientSecret := "ta-" + utils.GenerateString(61)
|
||||
|
||||
fmt.Printf("Client Name: %s\n", clientName)
|
||||
fmt.Printf("Client ID: %s\n", clientId)
|
||||
fmt.Printf("Client Secret: %s\n", clientSecret)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user