@@ -51,6 +51,7 @@ func TestRequestCode(t *testing.T) {
5151 url string
5252 clientID string
5353 scopes []string
54+ audience string
5455 }
5556 tests := []struct {
5657 name string
@@ -126,6 +127,42 @@ func TestRequestCode(t *testing.T) {
126127 },
127128 },
128129 },
130+ {
131+ name : "with audience" ,
132+ args : args {
133+ http : apiClient {
134+ stubs : []apiStub {
135+ {
136+ 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" ,
137+ status : 200 ,
138+ contentType : "application/x-www-form-urlencoded; charset=utf-8" ,
139+ },
140+ },
141+ },
142+ url : "https://github.com/oauth" ,
143+ clientID : "CLIENT-ID" ,
144+ scopes : []string {"repo" , "gist" },
145+ audience : "https://api.github.com" ,
146+ },
147+ want : & CodeResponse {
148+ DeviceCode : "DEVIC" ,
149+ UserCode : "123-abc" ,
150+ VerificationURI : "http://verify.me" ,
151+ VerificationURIComplete : "http://verify.me/?code=123-abc" ,
152+ ExpiresIn : 99 ,
153+ Interval : 5 ,
154+ },
155+ posts : []postArgs {
156+ {
157+ url : "https://github.com/oauth" ,
158+ params : url.Values {
159+ "client_id" : {"CLIENT-ID" },
160+ "scope" : {"repo gist" },
161+ "audience" : {"https://api.github.com" },
162+ },
163+ },
164+ },
165+ },
129166 {
130167 name : "unsupported" ,
131168 args : args {
@@ -237,7 +274,8 @@ func TestRequestCode(t *testing.T) {
237274 }
238275 for _ , tt := range tests {
239276 t .Run (tt .name , func (t * testing.T ) {
240- got , err := RequestCode (& tt .args .http , tt .args .url , tt .args .clientID , tt .args .scopes )
277+ got , err := RequestCode (& tt .args .http , tt .args .url ,
278+ tt .args .clientID , tt .args .scopes , WithAudience (tt .args .audience ))
241279 if (err != nil ) != (tt .wantErr != "" ) {
242280 t .Errorf ("RequestCode() error = %v, wantErr %v" , err , tt .wantErr )
243281 return
0 commit comments