From 957e700563c9ca9b05cea7cc1be9854bfb9dcf7f Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Fri, 11 Feb 2022 08:44:57 +0100 Subject: [PATCH] Allow custom client ID and scope when generating JWT from CLI --- auth/commands/commands.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/auth/commands/commands.go b/auth/commands/commands.go index fa9921d61..6d15fbd2e 100644 --- a/auth/commands/commands.go +++ b/auth/commands/commands.go @@ -31,6 +31,9 @@ func Command(ctx context.Context, app serviceInitializer, storeInit func(ctx con var ( enableDiscoveredProvider bool skipValidationOnAutoDiscoveredProvider bool + + clientID uint64 + scope []string ) cmd := &cobra.Command{ @@ -104,16 +107,34 @@ func Command(ctx context.Context, app serviceInitializer, storeInit func(ctx con err = service.DefaultAuth.LoadRoleMemberships(ctx, user) cli.HandleError(err) - signedToken, err = auth.TokenIssuer.Issue(ctx, + opts := []auth.IssueOptFn{ auth.WithIdentity(user), - auth.WithScope("profile", "api"), - ) + auth.WithScope(scope...), + } + + if clientID > 0 { + opts = append(opts, auth.WithClientID(clientID)) + } + + signedToken, err = auth.TokenIssuer.Issue(ctx, opts...) cli.HandleError(err) cmd.Println(string(signedToken)) }, } + jwtCmd.Flags().Uint64Var( + &clientID, + "auth-client", + 0, + "ID if the auth client") + + jwtCmd.Flags().StringArrayVar( + &scope, + "scope", + []string{"profile", "api"}, + "Scope") + testEmails := &cobra.Command{ Use: "test-notifications [recipient]", Short: "Sends samples of all authentication notification to recipient",