Skip to content

Commit 50e5f50

Browse files
authored
auth: revert to old /users/login endpoint for issuing tokens (#110)
fixes #108 the new endpoint has some additional restrictions that we weren't aware of. we're still tracking down what those restrictions are and what we should recommend users do instead. for now, just revert to the old route, so we have time to write appropriate docs on how to migrate. Signed-off-by: Nick Santos <[email protected]>
1 parent a75fab7 commit 50e5f50

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

internal/auth/token.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ func (p *LoginTokenProvider) EnsureToken(ctx context.Context) (string, error) {
6262

6363
// Request new token
6464
auth := struct {
65-
Identifier string `json:"identifier"`
66-
Secret string `json:"secret"`
65+
Username string `json:"username"`
66+
Password string `json:"password"`
6767
}{
68-
Identifier: p.username,
69-
Secret: p.password,
68+
Username: p.username,
69+
Password: p.password,
7070
}
7171

7272
authJSON, err := json.Marshal(auth)
7373
if err != nil {
7474
return "", fmt.Errorf("marshal auth: %v", err)
7575
}
7676

77-
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/auth/token", p.baseURL), bytes.NewBuffer(authJSON))
77+
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/users/login", p.baseURL), bytes.NewBuffer(authJSON))
7878
if err != nil {
7979
return "", err
8080
}
@@ -91,14 +91,14 @@ func (p *LoginTokenProvider) EnsureToken(ctx context.Context) (string, error) {
9191
}
9292

9393
var tokenResponse struct {
94-
AccessToken string `json:"access_token"`
94+
Token string `json:"token"`
9595
}
9696
if err := json.NewDecoder(res.Body).Decode(&tokenResponse); err != nil {
9797
return "", fmt.Errorf("decode token response: %v", err)
9898
}
9999

100100
// Parse token expiry
101-
claims, err := getClaims(tokenResponse.AccessToken)
101+
claims, err := getClaims(tokenResponse.Token)
102102
if err != nil {
103103
return "", fmt.Errorf("parse token claims: %v", err)
104104
}
@@ -107,7 +107,7 @@ func (p *LoginTokenProvider) EnsureToken(ctx context.Context) (string, error) {
107107
}
108108

109109
// Cache the token
110-
p.token = tokenResponse.AccessToken
110+
p.token = tokenResponse.Token
111111
p.tokenExpiry = claims.Expiry.Time()
112112

113113
return p.token, nil

0 commit comments

Comments
 (0)