@@ -4,6 +4,7 @@ import { generateCodeVerifier, generateCodeChallenge, generateState } from '../.
44import { buildAuthConfig } from '../../utils/auth-config' ;
55import { CallbackServer } from './callback-server' ;
66import { BrowserManager } from './browser' ;
7+ import { detectDeviceInfo } from '../../utils/device-detection' ;
78import {
89 AuthenticationResult ,
910 AuthenticationOptions ,
@@ -158,19 +159,31 @@ export class OAuth2Client {
158159 codeVerifier : string ;
159160 } ) : Promise < TokenResponse > {
160161 try {
162+ // Detect device information for automatic registration
163+ const deviceInfo = await detectDeviceInfo ( ) ;
164+
165+ // Add device_name field required by backend schema
166+ const deviceInfoWithName = {
167+ device_name : deviceInfo . hostname , // Use hostname as default device name
168+ ...deviceInfo
169+ } ;
170+
171+ const requestBody = {
172+ grant_type : 'authorization_code' ,
173+ code : params . code ,
174+ redirect_uri : this . config . redirectUri ,
175+ client_id : this . config . clientId ,
176+ code_verifier : params . codeVerifier ,
177+ device_info : deviceInfoWithName
178+ } ;
179+
161180 const response = await fetch ( this . config . tokenUrl , {
162181 method : 'POST' ,
163182 headers : {
164183 'Content-Type' : 'application/json' ,
165184 'User-Agent' : 'DeployStack-Gateway-CLI/0.2.0'
166185 } ,
167- body : JSON . stringify ( {
168- grant_type : 'authorization_code' ,
169- code : params . code ,
170- redirect_uri : this . config . redirectUri ,
171- client_id : this . config . clientId ,
172- code_verifier : params . codeVerifier
173- } )
186+ body : JSON . stringify ( requestBody )
174187 } ) ;
175188
176189 if ( ! response . ok ) {
@@ -182,7 +195,14 @@ export class OAuth2Client {
182195 ) ;
183196 }
184197
185- return await response . json ( ) as TokenResponse ;
198+ const tokenResponse = await response . json ( ) as TokenResponse ;
199+
200+ // Log device registration success if device info is included in response
201+ if ( tokenResponse . device ) {
202+ console . log ( chalk . green ( `📱 Device registered: ${ tokenResponse . device . device_name } ` ) ) ;
203+ }
204+
205+ return tokenResponse ;
186206 } catch ( error ) {
187207 if ( error instanceof AuthenticationError ) {
188208 throw error ;
0 commit comments