MCPcopy Create free account
hub / github.com/auth0/auth0-cli / testTokenCmd

Function testTokenCmd

internal/cli/test.go:204–327  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

202}
203
204func testTokenCmd(cli *cli) *cobra.Command {
205 var inputs testCmdInputs
206
207 cmd := &cobra.Command{
208 Use: "token",
209 Args: cobra.MaximumNArgs(1),
210 Short: "Request an access token for a given application and API",
211 Long: "Request an access token for a given application. " +
212 "Specify the API you want this token for with `--identifier` (API Identifier). " +
213 "Additionally, you can also specify the `--scopes` to grant.",
214 Example: ` auth0 test token
215 auth0 test token <client-id> --identifier <api-identifier> --organization <org-id> --scopes <scope1,scope2> --params "foo=bar"
216 auth0 test token <client-id> -a <api-identifier> -o <org-id> -s <scope1,scope2>
217 auth0 test token <client-id> -a <api-identifier> -s <scope1,scope2> --force
218 auth0 test token <client-id> -a <api-identifier> -o <org-id> -s <scope1,scope2> -p "foo=bar" -p "bazz=buzz" --force
219 auth0 test token <client-id> -a <api-identifier> -s <scope1,scope2> --json
220 auth0 test token <client-id> -a <api-identifier> -s <scope1,scope2> --json-compact
221 auth0 test token <client-id> -a <api-identifier> -o <org-id> -s <scope1,scope2> -p "foo=bar","bazz=buzz" --json
222 auth0 test token <client-id> -a <api-identifier> -s <scope1,scope2> --force --json`,
223 RunE: func(cmd *cobra.Command, args []string) error {
224 var tokenResponse *authutil.TokenResponse
225
226 client, err := selectClientToUseForTestsAndValidateExistence(cli, cmd, args, &inputs)
227 if err != nil {
228 return err
229 }
230
231 if err := testAudienceRequired.Pick(
232 cmd,
233 &inputs.Audience,
234 cli.audiencePickerOptions(client),
235 ); err != nil {
236 return err
237 }
238
239 cli.renderer.Infof("Domain : " + ansi.Blue(cli.tenant))
240 cli.renderer.Infof("Client ID : " + ansi.Bold(client.GetClientID()))
241 cli.renderer.Infof("Type : " + display.ApplyColorToFriendlyAppType(display.FriendlyAppType(client.GetAppType())))
242 cli.renderer.Newline()
243
244 // Deferred function to handle token rendering and clipboard copying.
245 defer func() {
246 if tokenResponse != nil {
247 cli.renderer.TestToken(client, tokenResponse)
248 if err := clipboard.WriteAll(tokenResponse.AccessToken); err != nil {
249 cli.renderer.Errorf("❌ Failed to copy the token to clipboard: %v", err)
250 } else {
251 cli.renderer.Infof("✅ Access Token copied to clipboard!\n")
252 }
253 }
254 }()
255
256 if client.GetAppType() == appTypeNonInteractive {
257 if len(inputs.Scopes) != 0 {
258 cli.renderer.Warnf("Passed in scopes do not apply to Machine to Machine applications.\n")
259 }
260
261 if err := cli.pickOrganizationForGrantIfRequired(cmd, client, inputs.Audience, &inputs.Organization); err != nil {

Callers 1

testCmdFunction · 0.85

Calls 15

BlueFunction · 0.92
BoldFunction · 0.92
FriendlyAppTypeFunction · 0.92
runClientCredentialsFlowFunction · 0.85
runLoginFlowFunction · 0.85
resourceUsageTemplateFunction · 0.85
audiencePickerOptionsMethod · 0.80
InfofMethod · 0.80
NewlineMethod · 0.80

Tested by

no test coverage detected