Skip to content

Commit

Permalink
Return the optional verification_uri_complete
Browse files Browse the repository at this point in the history
Closes #26
  • Loading branch information
tchandelle committed Dec 15, 2022
1 parent ce77fe6 commit b3b400d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
13 changes: 8 additions & 5 deletions device/device_flow.go
Expand Up @@ -41,6 +41,8 @@ type CodeResponse struct {
UserCode string
// The verification URL where users need to enter the UserCode.
VerificationURI string
// The optional verification URL that includes the UserCode.
VerificationURIComplete string

// The device verification code is 40 characters and used to verify the device.
DeviceCode string
Expand Down Expand Up @@ -87,11 +89,12 @@ func RequestCode(c httpClient, uri string, clientID string, scopes []string) (*C
}

return &CodeResponse{
DeviceCode: resp.Get("device_code"),
UserCode: resp.Get("user_code"),
VerificationURI: verificationURI,
Interval: intervalSeconds,
ExpiresIn: expiresIn,
DeviceCode: resp.Get("device_code"),
UserCode: resp.Get("user_code"),
VerificationURI: verificationURI,
VerificationURIComplete: resp.Get("verification_uri_complete"),
Interval: intervalSeconds,
ExpiresIn: expiresIn,
}, nil
}

Expand Down
34 changes: 34 additions & 0 deletions device/device_flow_test.go
Expand Up @@ -90,6 +90,40 @@ func TestRequestCode(t *testing.T) {
},
},
},
{
name: "with verification_uri_complete",
args: args{
http: apiClient{
stubs: []apiStub{
{
body: "verification_uri=http://verify.me&interval=5&expires_in=99&device_code=DEVIC&user_code=123-abc&verification_uri_complete=http://verify.me/?code=123-abc",
status: 200,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
},
},
},
url: "https://github.com/oauth",
clientID: "CLIENT-ID",
scopes: []string{"repo", "gist"},
},
want: &CodeResponse{
DeviceCode: "DEVIC",
UserCode: "123-abc",
VerificationURI: "http://verify.me",
VerificationURIComplete: "http://verify.me/?code=123-abc",
ExpiresIn: 99,
Interval: 5,
},
posts: []postArgs{
{
url: "https://github.com/oauth",
params: url.Values{
"client_id": {"CLIENT-ID"},
"scope": {"repo gist"},
},
},
},
},
{
name: "unsupported",
args: args{
Expand Down

0 comments on commit b3b400d

Please sign in to comment.