aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-12 17:48:03 -0400
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-12 17:48:03 -0400
commit89a6541a90a01cfc2756c5144cd40223eac3deaa (patch)
tree3f4e16798db3c87443555d22fb8f4f15be6f29d3 /pkg
parenta6e6463f518fcdb52cc4d01642f438d68ad8df8d (diff)
downloadAtlas-89a6541a90a01cfc2756c5144cd40223eac3deaa.tar.gz
Atlas-89a6541a90a01cfc2756c5144cd40223eac3deaa.zip
pkg/origin, cmd/origin-login-test: Handle auth errors
Diffstat (limited to 'pkg')
-rw-r--r--pkg/origin/login.go28
-rw-r--r--pkg/origin/origin.go2
2 files changed, 30 insertions, 0 deletions
diff --git a/pkg/origin/login.go b/pkg/origin/login.go
index 010e4b4..db40072 100644
--- a/pkg/origin/login.go
+++ b/pkg/origin/login.go
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
+ "errors"
"fmt"
"io"
"math/rand"
@@ -19,6 +20,8 @@ import (
"golang.org/x/net/html/atom"
)
+var ErrInvalidLogin = errors.New("invalid credentials")
+
type SID string
type NucleusToken string
@@ -316,6 +319,29 @@ func login2(ctx context.Context, c *http.Client, r1 *http.Request) (*http.Reques
m := login2re.FindSubmatch(buf)
if m == nil {
+ if doc, err := html.Parse(bytes.NewReader(buf)); err == nil {
+ if n := cascadia.Query(doc, cascadia.MustCompile(`#errorCode[value]`)); n != nil {
+ for _, a := range n.Attr {
+ // based on origin login js
+ if a.Namespace == "" && strings.EqualFold(a.Key, "value") {
+ switch errCode := a.Val; errCode {
+ case "10001": // try offline auth
+ return nil, fmt.Errorf("submit login form: ea auth error %s: why the fuck does origin think we're offline", errCode)
+ case "10002": // credentials
+ return nil, fmt.Errorf("submit login form: ea auth error %s: %w", errCode, ErrInvalidLogin)
+ case "10003": // general error
+ return nil, fmt.Errorf("submit login form: ea auth error %s: login error", errCode)
+ case "10004": // wtf
+ return nil, fmt.Errorf("submit login form: ea auth error %s: idk wtf this is", errCode)
+ case "":
+ // no error, but this shouldn't happen
+ default:
+ return nil, fmt.Errorf("submit login form: ea auth error %s", errCode)
+ }
+ }
+ }
+ }
+ }
return nil, fmt.Errorf("submit login form: could not find JS redirect URL")
}
@@ -376,6 +402,8 @@ func login3(_ context.Context, c *http.Client, r2 *http.Request) (string, error)
// GetNucleusToken generates a Nucleus SID/AuthToken from the active session.
// Note that this token generally lasts ~4h.
+//
+// If errors.Is(err, ErrAuthRequired), you need a new SID.
func GetNucleusToken(ctx context.Context, sid SID) (NucleusToken, error) {
jar, _ := cookiejar.New(nil)
diff --git a/pkg/origin/origin.go b/pkg/origin/origin.go
index ecc667f..7f7abb7 100644
--- a/pkg/origin/origin.go
+++ b/pkg/origin/origin.go
@@ -31,6 +31,8 @@ type UserInfo struct {
}
// GetUserInfo gets information about Origin accounts by their Origin UserID.
+//
+// If errors.Is(err, ErrAuthRequired), you need a new NucleusToken.
func GetUserInfo(ctx context.Context, token NucleusToken, uid ...int) ([]UserInfo, error) {
uids := make([]string, len(uid))
for _, x := range uid {