reduce scope to read for now; confirm successful login
This commit is contained in:
parent
d3c67562ec
commit
6c297e5242
2 changed files with 12 additions and 9 deletions
14
config.go
14
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) {
|
||||
|
|
7
login.go
7
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",
|
||||
|
|
Loading…
Reference in a new issue