@@ -63,28 +63,36 @@ public AccountDriver(ITestOutputHelper testOutputHelper, HttpClient httpClient,
6363
6464 public async Task < LoginResponse ? > Login ( string emailAddress , string password )
6565 {
66- _testOutputHelper . WriteLine ( "Starting login request" ) ;
67-
68- var requestBody = JsonSerializer . Serialize ( new
66+ _testOutputHelper . WriteLine ( "Starting OAuth2.0 login request" ) ;
67+
68+ var requestBody = new List < KeyValuePair < string , string > >
6969 {
70- emailAddress ,
71- password
72- } ) ;
70+ new ( "grant_type" , "password" ) ,
71+ new ( "username" , emailAddress ) ,
72+ new ( "password" , password ) ,
73+ new ( "client_id" , "user-authentication" ) , // Replace with your client_id
74+ new ( "client_secret" , "388D45FA-B36B-4988-BA59-B187D329C207" ) // Replace with your client_secret
75+ } ;
7376
74- var loginResult = await _httpClient . PostAsync ( "api/users/v1/login" ,
75- new StringContent ( requestBody , Encoding . Default , "application/json" ) ) ;
77+ var requestContent = new FormUrlEncodedContent ( requestBody ) ;
78+ var tokenResult = await _httpClient . PostAsync ( "api/users/v1/login" , requestContent ) ; // Use the original endpoint
7679
77- _testOutputHelper . WriteLine ( $ "Login status code is { loginResult . StatusCode } ") ;
80+ _testOutputHelper . WriteLine ( $ "OAuth2.0 token status code is { tokenResult . StatusCode } ") ;
7881
79- var loginResultBody = await loginResult . Content . ReadAsStringAsync ( ) ;
82+ var tokenResultBody = await tokenResult . Content . ReadAsStringAsync ( ) ;
83+ if ( string . IsNullOrEmpty ( tokenResultBody ) ) return null ;
8084
81- if ( string . IsNullOrEmpty ( loginResultBody ) ) return null ;
85+ using var doc = JsonDocument . Parse ( tokenResultBody ) ;
86+ if ( ! doc . RootElement . TryGetProperty ( "access_token" , out var accessTokenElement ) )
87+ return null ;
8288
83- var parsedBody = JsonSerializer . Deserialize < ApiResponse < LoginResponse > > ( loginResultBody ) ;
89+ var accessToken = accessTokenElement . GetString ( ) ;
90+ var expiresIn = doc . RootElement . TryGetProperty ( "expires_in" , out var expiresInElement ) ? expiresInElement . GetInt32 ( ) : 0 ;
8491
85- return loginResult . IsSuccessStatusCode
86- ? parsedBody ? . Data
87- : null ;
92+ return new LoginResponse
93+ {
94+ AuthToken = accessToken ?? string . Empty
95+ } ;
8896 }
8997
9098 public async Task < UserAccountDTO ? > GetUserAccount ( string authToken )
@@ -110,4 +118,4 @@ public async Task InjectStickerClaimedMessage(string userId, string stickerId)
110118 stickerId = stickerId
111119 } ) ;
112120 }
113- }
121+ }
0 commit comments