diff --git a/config.go b/config.go index b325198..ca454b1 100644 --- a/config.go +++ b/config.go @@ -21,9 +21,9 @@ type Authentication struct { AccessToken string `json:"accessToken"` } -func saveAuthenticationConfig(username string, authentication Authentication) error { +func saveAuthenticationConfig(username string, authentication Authentication) (string, error) { if err := ensureConfigDir(); err != nil { - return fmt.Errorf("unable to ensure the configuration directory; %w", err) + return "", fmt.Errorf("unable to ensure the configuration directory; %w", err) } var config AuthenticationConfig @@ -32,14 +32,14 @@ func saveAuthenticationConfig(username string, authentication Authentication) er if _, err := os.Stat(filepath); err != nil { if !errors.Is(err, os.ErrNotExist) { - return fmt.Errorf("unknown error received when running stat on %s; %w", filepath, err) + return "", fmt.Errorf("unknown error received when running stat on %s; %w", filepath, err) } config.Authentications = make(map[string]Authentication) } else { config, err = newAuthenticationConfigFromFile() if err != nil { - return fmt.Errorf("unable to retrieve the existing authentication configuration; %w", err) + return "", fmt.Errorf("unable to retrieve the existing authentication configuration; %w", err) } } @@ -59,14 +59,14 @@ func saveAuthenticationConfig(username string, authentication Authentication) er file, err := os.Create(authenticationConfigFile()) if err != nil { - return fmt.Errorf("unable to open the config file; %w", err) + return "", fmt.Errorf("unable to open the config file; %w", err) } if err := json.NewEncoder(file).Encode(config); err != nil { - return fmt.Errorf("unable to save the JSON data to the authentication config file; %w", err) + return "", fmt.Errorf("unable to save the JSON data to the authentication config file; %w", err) } - return nil + return authenticationName, nil } func newAuthenticationConfigFromFile() (AuthenticationConfig, error) { diff --git a/login.go b/login.go index ca5602f..c7c6a65 100644 --- a/login.go +++ b/login.go @@ -76,10 +76,13 @@ func loginWithOauth2() error { return fmt.Errorf("unable to verify the credentials; %w", err) } - if err := saveAuthenticationConfig(account.Username, client.authentication); err != nil { + loginName, err := saveAuthenticationConfig(account.Username, client.authentication) + if err != nil { return fmt.Errorf("unable to save the authentication details; %w", err) } + fmt.Printf("Successfully logged into %s\n", loginName) + return nil } @@ -87,7 +90,7 @@ func authCodeURL(account Authentication) string { config := oauth2.Config{ ClientID: account.ClientID, ClientSecret: account.ClientSecret, - Scopes: []string{"read", "write"}, + Scopes: []string{"read"}, RedirectURL: redirectUri, Endpoint: oauth2.Endpoint{ AuthURL: account.Instance + "/oauth/authorize",