Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions login.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,28 @@ func v2login(email, password, secondFactor string) (string, error) {
err = errors.New(errorStr)
}
ExitIfError(err, false)
if res.StatusCode == 403 {
switch res.StatusCode {
case 200:
var response struct {
APIKey string `json:"api_key"`
}
ExitIfError(res.Body.FromJsonTo(&response), false)
return response.APIKey, nil
case 401:
var response struct {
Error string `json:"error"`
}
ExitIfError(res.Body.FromJsonTo(&response), false)
return "", errors.New(response.Error)
case 403:
return v2login(email, password, getString("Two-factor code: "))
case 404:
return "", errors.New("Authentication failed.\nEmail or password is not valid.\nCheck your credentials on https://dashboard.heroku.com")
default:
body, err := res.Body.ToString()
PrintError(err, false)
return "", fmt.Errorf("Invalid response from API.\nHTTP %d\n%s\n\nAre you behind a proxy?\nhttps://devcenter.heroku.com/articles/using-the-cli#using-an-http-proxy", res.StatusCode, body)
}
if res.StatusCode == 404 {
return "", errors.New("Authentication failure.")
}
if res.StatusCode != 200 {
return "", errors.New("Invalid response from API.\nAre you behind a proxy?\nhttps://devcenter.heroku.com/articles/using-the-cli#using-an-http-proxy")
}
type Doc struct {
APIKey string `json:"api_key"`
}
var doc Doc
ExitIfError(res.Body.FromJsonTo(&doc), false)
return doc.APIKey, nil
}

func createOauthToken(email, password, secondFactor string) (string, error) {
Expand Down