Skip to content

Commit 549316c

Browse files
committed
better
1 parent fa29458 commit 549316c

File tree

4 files changed

+4
-32
lines changed

4 files changed

+4
-32
lines changed

deviceauth.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212

1313
"golang.org/x/net/context/ctxhttp"
14-
"golang.org/x/oauth2/internal"
1514
)
1615

1716
const (
@@ -70,17 +69,3 @@ func retrieveDeviceAuth(ctx context.Context, c *Config, v url.Values) (*DeviceAu
7069

7170
return da, nil
7271
}
73-
74-
func parseError(err error) string {
75-
e, ok := err.(*RetrieveError)
76-
if ok {
77-
eResp := make(map[string]string)
78-
_ = json.Unmarshal(e.Body, &eResp)
79-
return eResp["error"]
80-
}
81-
e2, ok := err.(*internal.TokenError)
82-
if ok {
83-
return e2.Err
84-
}
85-
return ""
86-
}

github/github.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
package github // import "golang.org/x/oauth2/github"
77

88
import (
9-
"golang.org/x/oauth2"
9+
"golang.org/x/oauth2/endpoints"
1010
)
1111

1212
// Endpoint is Github's OAuth 2.0 endpoint.
13-
var Endpoint = oauth2.Endpoint{
14-
AuthURL: "https://github.com/login/oauth/authorize",
15-
TokenURL: "https://github.com/login/oauth/access_token",
16-
}
13+
var Endpoint = endpoints.GitHub

internal/token.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,3 @@ type RetrieveError struct {
323323
func (r *RetrieveError) Error() string {
324324
return fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", r.Response.Status, r.Body)
325325
}
326-
327-
type TokenError struct {
328-
Err string
329-
ErrorDescription string
330-
ErrorURI string
331-
}
332-
333-
func (t *TokenError) Error() string {
334-
return fmt.Sprintf("oauth2: error in token fetch response: %s\nerror_description: %s\nerror_uri: %s", t.Err, t.ErrorDescription, t.ErrorURI)
335-
}

oauth2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ func (c *Config) Poll(ctx context.Context, da *DeviceAuth, opts ...AuthCodeOptio
270270
return tok, nil
271271
}
272272

273-
errTyp := parseError(err)
274-
switch errTyp {
273+
e, _ := err.(*RetrieveError)
274+
switch e.ErrorCode {
275275
case errSlowDown:
276276
interval += 5
277277
case errAuthorizationPending:

0 commit comments

Comments
 (0)