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

Function promptDefaultURLs

internal/cli/quickstarts.go:272–328  ·  view source on GitHub ↗

promptDefaultURLs checks whether the application is SPA or WebApp and whether the app has already added the default quickstart url to allowed url lists. If not, it prompts the user to add the default url and updates the application if they accept.

(ctx context.Context, cli *cli, client *management.Client, qsType string, qsStack string)

Source from the content-addressed store, hash-verified

270// If not, it prompts the user to add the default url and updates the application
271// if they accept.
272func promptDefaultURLs(ctx context.Context, cli *cli, client *management.Client, qsType string, qsStack string) error {
273 defaultURL := defaultURLFor(qsStack)
274 defaultCallbackURL := defaultCallbackURLFor(qsStack)
275
276 if !strings.EqualFold(qsType, qsSpa) && !strings.EqualFold(qsType, qsWebApp) {
277 return nil
278 }
279
280 a := &management.Client{
281 Callbacks: client.Callbacks,
282 AllowedLogoutURLs: client.AllowedLogoutURLs,
283 AllowedOrigins: client.AllowedOrigins,
284 WebOrigins: client.WebOrigins,
285 }
286
287 if !containsStr(client.GetCallbacks(), defaultCallbackURL) {
288 callbacks := append(client.GetCallbacks(), defaultCallbackURL)
289 a.Callbacks = &callbacks
290 }
291
292 if !containsStr(client.GetAllowedLogoutURLs(), defaultURL) {
293 allowedLogoutURLs := append(a.GetAllowedLogoutURLs(), defaultURL)
294 a.AllowedLogoutURLs = &allowedLogoutURLs
295 }
296
297 if strings.EqualFold(qsType, qsSpa) {
298 if !containsStr(client.GetAllowedOrigins(), defaultURL) {
299 allowedOrigins := append(a.GetAllowedOrigins(), defaultURL)
300 a.AllowedOrigins = &allowedOrigins
301 }
302
303 if !containsStr(client.GetWebOrigins(), defaultURL) {
304 webOrigins := append(a.GetWebOrigins(), defaultURL)
305 a.WebOrigins = &webOrigins
306 }
307 }
308
309 callbackURLChanged := len(client.GetCallbacks()) != len(a.GetCallbacks())
310 otherURLsChanged := len(client.GetAllowedLogoutURLs()) != len(a.GetAllowedLogoutURLs()) ||
311 len(client.GetAllowedOrigins()) != len(a.GetAllowedOrigins()) ||
312 len(client.GetWebOrigins()) != len(a.GetWebOrigins())
313
314 if !callbackURLChanged && !otherURLsChanged {
315 return nil
316 }
317
318 if confirmed := prompt.Confirm(urlPromptFor(qsType, qsStack)); confirmed {
319 err := ansi.Waiting(func() error {
320 return cli.api.Client.Update(ctx, client.GetClientID(), a)
321 })
322 if err != nil {
323 return err
324 }
325 cli.renderer.Infof("Application successfully updated")
326 }
327 return nil
328}
329

Callers 1

downloadQuickstartFunction · 0.85

Calls 8

ConfirmFunction · 0.92
WaitingFunction · 0.92
defaultURLForFunction · 0.85
defaultCallbackURLForFunction · 0.85
containsStrFunction · 0.85
urlPromptForFunction · 0.85
InfofMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected