MCPcopy
hub / github.com/ory/hydra / NewImportClientCmd

Function NewImportClientCmd

cmd/cmd_import_client.go:22–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20)
21
22func NewImportClientCmd() *cobra.Command {
23 cmd := &cobra.Command{
24 Use: "oauth2-client <file-1.json> [<file-2.json> ...]",
25 Aliases: []string{"client", "clients", "oauth2-clients"},
26 Short: "Import one or more OAuth 2.0 Clients from files or STDIN",
27 Example: `Import an example OAuth2 Client:
28 cat > ./file.json <<EOF
29 [
30 {
31 "grant_types": ["implicit"],
32 "scope": "openid"
33 },
34 {
35 "grant_types": ["authorize_code"],
36 "scope": "openid"
37 }
38 ]
39 EOF
40
41 {{ .CommandPath }} file.json
42
43Alternatively:
44
45 cat file.json | {{ .CommandPath }}
46
47To encrypt an auto-generated OAuth2 Client Secret, use flags ` + "`--pgp-key`" + `, ` + "`--pgp-key-url`" + ` or ` + "`--keybase`" + ` flag, for example:
48
49 {{ .CommandPath }} --name "my app" --grant-type client_credentials --response-type token --scope core,foobar --keybase keybase_username
50`,
51 Long: `This command reads in each listed JSON file and imports their contents as a list of OAuth 2.0 Clients.
52
53The format for the JSON file is:
54
55[
56 {
57 "client_secret": "...",
58 // ... all other fields of the OAuth 2.0 Client model are allowed here
59 }
60]
61
62Please be aware that this command does not update existing clients. If the client exists already, this command will fail.`,
63 RunE: func(cmd *cobra.Command, args []string) error {
64 m, _, err := cliclient.NewClient(cmd)
65 if err != nil {
66 return err
67 }
68
69 ek, encryptSecret, err := cli.NewEncryptionKey(cmd, nil)
70 if err != nil {
71 _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Failed to load encryption key: %s", err)
72 return cmdx.FailSilently(cmd)
73 }
74
75 streams := map[string]io.Reader{"STDIN": cmd.InOrStdin()}
76 for _, path := range args {
77 contents, err := os.ReadFile(path) // #nosec G304
78 if err != nil {
79 _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not open file %s: %s", path, err)

Callers 2

TestImportClientFunction · 0.92
RegisterCommandRecursiveFunction · 0.85

Calls 9

NewClientFunction · 0.92
NewEncryptionKeyFunction · 0.92
registerEncryptFlagsFunction · 0.85
CreateOAuth2ClientMethod · 0.80
DecodeMethod · 0.65
EncryptMethod · 0.65
IsMethod · 0.45
ExecuteMethod · 0.45
OAuth2ClientMethod · 0.45

Tested by 1

TestImportClientFunction · 0.74