MCPcopy Create free account
hub / github.com/Scalingo/cli / Auth

Function Auth

config/auth.go:32–66  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

30)
31
32func Auth(ctx context.Context) (*scalingo.User, string, error) {
33 var user *scalingo.User
34 var tokens string
35 var err error
36
37 if C.DisableInteractive {
38 err = errors.New(ctx, "Fail to login (interactive mode disabled)")
39 } else {
40 for i := range 3 {
41 user, tokens, err = tryAuth(ctx)
42 if err == nil {
43 break
44 } else if errors.Is(err, io.EOF) {
45 return nil, "", errors.New(ctx, "canceled by user")
46 } else {
47 appio.Errorf("Fail to login (%d/3): %v\n\n", i+1, err)
48 }
49 }
50 }
51 if err == ErrAuthenticationFailed {
52 return nil, "", errors.New(ctx, "Forgot your password? https://auth.scalingo.com")
53 }
54 if err != nil {
55 return nil, "", errors.Wrapf(ctx, err, "authentication failed")
56 }
57
58 fmt.Print("\n")
59 appio.Statusf("Hello %s, nice to see you!\n\n", user.Username)
60 err = SetCurrentUser(ctx, user, tokens)
61 if err != nil {
62 return nil, "", errors.Wrapf(ctx, err, "set current user")
63 }
64
65 return user, tokens, nil
66}
67
68func SetCurrentUser(ctx context.Context, user *scalingo.User, token string) error {
69 authenticator := &CliAuthenticator{}

Callers 1

loginWithUserAndPasswordFunction · 0.92

Calls 2

tryAuthFunction · 0.85
SetCurrentUserFunction · 0.85

Tested by

no test coverage detected