MCPcopy
hub / github.com/smallstep/cli / DoManualAuthorization

Method DoManualAuthorization

command/oauth/cmd.go:819–846  ·  view source on GitHub ↗

DoManualAuthorization performs the log in into the identity provider allowing the user to open a browser on a different system and then entering the authorization code on the Step CLI.

()

Source from the content-addressed store, hash-verified

817// allowing the user to open a browser on a different system and then entering
818// the authorization code on the Step CLI.
819func (o *oauth) DoManualAuthorization() (*token, error) {
820 o.redirectURI = oobCallbackUrn
821 authURL, err := o.Auth()
822 if err != nil {
823 return nil, err
824 }
825
826 fmt.Fprintln(os.Stderr, "Open a local web browser and visit:")
827 fmt.Fprintln(os.Stderr)
828 fmt.Fprintln(os.Stderr, authURL)
829 fmt.Fprintln(os.Stderr)
830
831 // Read from the command line
832 fmt.Fprint(os.Stderr, "Enter verification code: ")
833 code, err := utils.ReadString(os.Stdin)
834 if err != nil {
835 return nil, errors.WithStack(err)
836 }
837
838 tok, err := o.Exchange(o.tokenEndpoint, code)
839 if err != nil {
840 return nil, err
841 }
842 if tok.Err != "" || tok.ErrDesc != "" {
843 return nil, errors.Errorf("Error exchanging authorization code: %s. %s", tok.Err, tok.ErrDesc)
844 }
845 return tok, nil
846}
847
848type identifyDeviceResponse struct {
849 DeviceCode string `json:"device_code"`

Callers 1

oauthCmdFunction · 0.80

Calls 3

AuthMethod · 0.95
ExchangeMethod · 0.95
ReadStringFunction · 0.92

Tested by

no test coverage detected