| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Package authcli implements authentication related flags parsing and CLI | 5 // Package authcli implements authentication related flags parsing and CLI |
| 6 // subcommands. | 6 // subcommands. |
| 7 // | 7 // |
| 8 // It can be used from CLI tools that want customize authentication | 8 // It can be used from CLI tools that want customize authentication |
| 9 // configuration from the command line. | 9 // configuration from the command line. |
| 10 // | 10 // |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } else { | 496 } else { |
| 497 // An authenticator preconfigured with given list of scopes. | 497 // An authenticator preconfigured with given list of scopes. |
| 498 logging.Debugf(ctx, "Using rigid token generator: %s (scopes %s)
", opts.Method, opts.Scopes) | 498 logging.Debugf(ctx, "Using rigid token generator: %s (scopes %s)
", opts.Method, opts.Scopes) |
| 499 gen, err = localauth.NewRigidGenerator(ctx, authenticator) | 499 gen, err = localauth.NewRigidGenerator(ctx, authenticator) |
| 500 } | 500 } |
| 501 if err != nil { | 501 if err != nil { |
| 502 fmt.Fprintln(os.Stderr, err) | 502 fmt.Fprintln(os.Stderr, err) |
| 503 return ExitCodeNoValidToken | 503 return ExitCodeNoValidToken |
| 504 } | 504 } |
| 505 | 505 |
| 506 // We currently always setup a context with one account (which is also |
| 507 // default). To avoid confusion where it comes from, we name it 'authuti
l'. |
| 508 // Most tools should not care how it is named, as long as it is specifie
d as |
| 509 // 'default_account_id' in LUCI_CONTEXT["local_auth"]. |
| 510 srv := &localauth.Server{ |
| 511 TokenGenerators: map[string]localauth.TokenGenerator{ |
| 512 "authutil": gen, |
| 513 }, |
| 514 DefaultAccountID: "authutil", |
| 515 } |
| 516 |
| 506 // Enter the environment with the local auth server. | 517 // Enter the environment with the local auth server. |
| 507 srv := &localauth.Server{TokenGenerator: gen} | |
| 508 err = localauth.WithLocalAuth(ctx, srv, func(ctx context.Context) error
{ | 518 err = localauth.WithLocalAuth(ctx, srv, func(ctx context.Context) error
{ |
| 509 // Put the new LUCI_CONTEXT file, prepare cmd environ. | 519 // Put the new LUCI_CONTEXT file, prepare cmd environ. |
| 510 exported, err := lucictx.Export(ctx, "") | 520 exported, err := lucictx.Export(ctx, "") |
| 511 if err != nil { | 521 if err != nil { |
| 512 logging.WithError(err).Errorf(ctx, "Failed to prepare LU
CI_CONTEXT file") | 522 logging.WithError(err).Errorf(ctx, "Failed to prepare LU
CI_CONTEXT file") |
| 513 return err | 523 return err |
| 514 } | 524 } |
| 515 defer func() { | 525 defer func() { |
| 516 if err := exported.Close(); err != nil { | 526 if err := exported.Close(); err != nil { |
| 517 logging.WithError(err).Warningf(ctx, "Failed to
remove LUCI_CONTEXT file") | 527 logging.WithError(err).Warningf(ctx, "Failed to
remove LUCI_CONTEXT file") |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 } | 578 } |
| 569 fmt.Printf("OAuth token details:\n") | 579 fmt.Printf("OAuth token details:\n") |
| 570 fmt.Printf(" Client ID: %s\n", info.Aud) | 580 fmt.Printf(" Client ID: %s\n", info.Aud) |
| 571 fmt.Printf(" Scopes:\n") | 581 fmt.Printf(" Scopes:\n") |
| 572 for _, scope := range strings.Split(info.Scope, " ") { | 582 for _, scope := range strings.Split(info.Scope, " ") { |
| 573 fmt.Printf(" %s\n", scope) | 583 fmt.Printf(" %s\n", scope) |
| 574 } | 584 } |
| 575 | 585 |
| 576 return ExitCodeSuccess | 586 return ExitCodeSuccess |
| 577 } | 587 } |
| OLD | NEW |