Skip to content

Commit adf5f73

Browse files
authored
Handle case when Device Flow is disabled for the OAuth app (cli#48)
1 parent d1a6431 commit adf5f73

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

device/device_flow.go

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func RequestCode(c httpClient, uri string, clientID string, scopes []string) (*C
7272

7373
if resp.StatusCode == 401 || resp.StatusCode == 403 || resp.StatusCode == 404 || resp.StatusCode == 422 ||
7474
(resp.StatusCode == 200 && verificationURI == "") ||
75+
(resp.StatusCode == 400 && resp.Get("error") == "device_flow_disabled") ||
7576
(resp.StatusCode == 400 && resp.Get("error") == "unauthorized_client") {
7677
return nil, ErrUnsupported
7778
}

device/device_flow_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,33 @@ func TestRequestCode(t *testing.T) {
180180
},
181181
},
182182
},
183+
{
184+
name: "device flow disabled",
185+
args: args{
186+
http: apiClient{
187+
stubs: []apiStub{
188+
{
189+
body: "error=device_flow_disabled",
190+
status: 400,
191+
contentType: "application/x-www-form-urlencoded; charset=utf-8",
192+
},
193+
},
194+
},
195+
url: "https://github.com/oauth",
196+
clientID: "CLIENT-ID",
197+
scopes: []string{"repo", "gist"},
198+
},
199+
wantErr: "device flow not supported",
200+
posts: []postArgs{
201+
{
202+
url: "https://github.com/oauth",
203+
params: url.Values{
204+
"client_id": {"CLIENT-ID"},
205+
"scope": {"repo gist"},
206+
},
207+
},
208+
},
209+
},
183210
{
184211
name: "server error",
185212
args: args{

0 commit comments

Comments
 (0)