@@ -10,6 +10,8 @@ namespace OneIdentity.SafeguardDotNet.DeviceCodeLogin;
1010using System . Threading ;
1111using System . Threading . Tasks ;
1212
13+ using OneIdentity . SafeguardDotNet . DeviceCodeLogin . Serialization ;
14+
1315using Serilog ;
1416
1517/// <summary>
@@ -87,7 +89,9 @@ public static async Task<ISafeguardConnection> ConnectAsync(
8789 Log . Debug ( "Requesting device authorization from {Appliance}" , appliance ) ;
8890
8991 var deviceAuthUrl = $ "https://{ appliance } /RSTS/oauth2/DeviceLogin";
90- var requestBody = JsonSerializer . Serialize ( new { client_id = clientId , scope } ) ;
92+ var requestBody = JsonSerializer . Serialize (
93+ new DeviceAuthRequest { ClientId = clientId , Scope = scope } ,
94+ DeviceCodeJsonContext . Default . DeviceAuthRequest ) ;
9195 var content = new StringContent ( requestBody , Encoding . UTF8 , "application/json" ) ;
9296
9397 HttpResponseMessage response ;
@@ -142,12 +146,14 @@ public static async Task<ISafeguardConnection> ConnectAsync(
142146
143147 await Task . Delay ( TimeSpan . FromSeconds ( intervalSeconds ) , cancellationToken ) . ConfigureAwait ( false ) ;
144148
145- var pollBody = JsonSerializer . Serialize ( new
146- {
147- grant_type = "urn:ietf:params:oauth:grant-type:device_code" ,
148- device_code = deviceCode ,
149- client_id = clientId ,
150- } ) ;
149+ var pollBody = JsonSerializer . Serialize (
150+ new DeviceTokenRequest
151+ {
152+ GrantType = "urn:ietf:params:oauth:grant-type:device_code" ,
153+ DeviceCode = deviceCode ,
154+ ClientId = clientId ,
155+ } ,
156+ DeviceCodeJsonContext . Default . DeviceTokenRequest ) ;
151157 var pollContent = new StringContent ( pollBody , Encoding . UTF8 , "application/json" ) ;
152158 var pollResponse = await http . PostAsync ( tokenUrl , pollContent , cancellationToken ) . ConfigureAwait ( false ) ;
153159 var pollResponseBody = await pollResponse . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
0 commit comments