Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
hickford committed Dec 30, 2022
1 parent fa29458 commit 549316c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 32 deletions.
15 changes: 0 additions & 15 deletions deviceauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"golang.org/x/net/context/ctxhttp"
"golang.org/x/oauth2/internal"
)

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

return da, nil
}

func parseError(err error) string {
e, ok := err.(*RetrieveError)
if ok {
eResp := make(map[string]string)
_ = json.Unmarshal(e.Body, &eResp)
return eResp["error"]
}
e2, ok := err.(*internal.TokenError)
if ok {
return e2.Err
}
return ""
}
7 changes: 2 additions & 5 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
package github // import "golang.org/x/oauth2/github"

import (
"golang.org/x/oauth2"
"golang.org/x/oauth2/endpoints"
)

// Endpoint is Github's OAuth 2.0 endpoint.
var Endpoint = oauth2.Endpoint{
AuthURL: "https://github.com/login/oauth/authorize",
TokenURL: "https://github.com/login/oauth/access_token",
}
var Endpoint = endpoints.GitHub
10 changes: 0 additions & 10 deletions internal/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,3 @@ type RetrieveError struct {
func (r *RetrieveError) Error() string {
return fmt.Sprintf("oauth2: cannot fetch token: %v\nResponse: %s", r.Response.Status, r.Body)
}

type TokenError struct {
Err string
ErrorDescription string
ErrorURI string
}

func (t *TokenError) Error() string {
return fmt.Sprintf("oauth2: error in token fetch response: %s\nerror_description: %s\nerror_uri: %s", t.Err, t.ErrorDescription, t.ErrorURI)
}
4 changes: 2 additions & 2 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ func (c *Config) Poll(ctx context.Context, da *DeviceAuth, opts ...AuthCodeOptio
return tok, nil
}

errTyp := parseError(err)
switch errTyp {
e, _ := err.(*RetrieveError)
switch e.ErrorCode {
case errSlowDown:
interval += 5
case errAuthorizationPending:
Expand Down

0 comments on commit 549316c

Please sign in to comment.