From b3b400db0414202303eef43e73e981ad706f67a0 Mon Sep 17 00:00:00 2001 From: Thomas Chandelle Date: Thu, 15 Dec 2022 11:53:23 +0100 Subject: [PATCH] Return the optional verification_uri_complete Closes #26 --- device/device_flow.go | 13 ++++++++----- device/device_flow_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/device/device_flow.go b/device/device_flow.go index 203a7ac..c665a5a 100644 --- a/device/device_flow.go +++ b/device/device_flow.go @@ -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 @@ -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 } diff --git a/device/device_flow_test.go b/device/device_flow_test.go index 91463e8..ba93139 100644 --- a/device/device_flow_test.go +++ b/device/device_flow_test.go @@ -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{