Skip to content

Commit

Permalink
Handle case when Device Flow is disabled for the OAuth app (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav authored Feb 2, 2023
1 parent d1a6431 commit adf5f73
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions device/device_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func RequestCode(c httpClient, uri string, clientID string, scopes []string) (*C

if resp.StatusCode == 401 || resp.StatusCode == 403 || resp.StatusCode == 404 || resp.StatusCode == 422 ||
(resp.StatusCode == 200 && verificationURI == "") ||
(resp.StatusCode == 400 && resp.Get("error") == "device_flow_disabled") ||
(resp.StatusCode == 400 && resp.Get("error") == "unauthorized_client") {
return nil, ErrUnsupported
}
Expand Down
27 changes: 27 additions & 0 deletions device/device_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ func TestRequestCode(t *testing.T) {
},
},
},
{
name: "device flow disabled",
args: args{
http: apiClient{
stubs: []apiStub{
{
body: "error=device_flow_disabled",
status: 400,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
},
},
},
url: "https://github.com/oauth",
clientID: "CLIENT-ID",
scopes: []string{"repo", "gist"},
},
wantErr: "device flow not supported",
posts: []postArgs{
{
url: "https://github.com/oauth",
params: url.Values{
"client_id": {"CLIENT-ID"},
"scope": {"repo gist"},
},
},
},
},
{
name: "server error",
args: args{
Expand Down

0 comments on commit adf5f73

Please sign in to comment.