File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed
Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 455455
456456#region InAppWallet - OAuth
457457
458- // var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Steam );
458+ // var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Github );
459459// if (!await inAppWalletOAuth.IsConnected())
460460// {
461461// _ = await inAppWalletOAuth.LoginWithOauth(
472472// var inAppWalletOAuthAddress = await inAppWalletOAuth.GetAddress();
473473// Console.WriteLine($"InAppWallet OAuth address: {inAppWalletOAuthAddress}");
474474
475+ // var inAppWalletAuthDetails = inAppWalletOAuth.GetUserAuthDetails();
476+ // Console.WriteLine($"InAppWallet OAuth auth details: {JsonConvert.SerializeObject(inAppWalletAuthDetails, Formatting.Indented)}");
477+
475478#endregion
476479
477480#region Smart Wallet - Gasless Transaction
Original file line number Diff line number Diff line change 55using Nethereum . Signer ;
66using Nethereum . Signer . EIP712 ;
77using Newtonsoft . Json ;
8+ using Newtonsoft . Json . Linq ;
89using Thirdweb . EWS ;
910
1011namespace Thirdweb ;
@@ -292,6 +293,55 @@ public async Task<UserStatusResponse> GetUserDetails()
292293 return await GetUserStatus ( this . HttpClient ) . ConfigureAwait ( false ) ;
293294 }
294295
296+ /// <summary>
297+ /// Gets the user auth details from the corresponding auth provider.
298+ /// </summary>
299+ /// <returns>The user auth details as a JObject</returns>
300+ public JObject GetUserAuthDetails ( )
301+ {
302+ var authToken = this . EmbeddedWallet . GetSessionData ( ) ? . AuthToken ;
303+ if ( string . IsNullOrEmpty ( authToken ) )
304+ {
305+ throw new InvalidOperationException ( "Cannot get user auth details without an active session." ) ;
306+ }
307+
308+ var parts = authToken . Split ( '.' ) ;
309+ if ( parts . Length != 3 )
310+ {
311+ Console . WriteLine ( "Invalid JWT" ) ;
312+ }
313+
314+ static string Base64UrlDecode ( string input )
315+ {
316+ var paddedInput = input . Replace ( '-' , '+' ) . Replace ( '_' , '/' ) ;
317+ switch ( paddedInput . Length % 4 )
318+ {
319+ case 2 :
320+ paddedInput += "==" ;
321+ break ;
322+ case 3 :
323+ paddedInput += "=" ;
324+ break ;
325+ default :
326+ break ;
327+ }
328+ var decodedBytes = Convert . FromBase64String ( paddedInput ) ;
329+ return Encoding . UTF8 . GetString ( decodedBytes ) ;
330+ }
331+
332+ var payload = JObject . Parse ( Base64UrlDecode ( parts [ 1 ] ) ) ;
333+ var jwtToken = payload [ "storedToken" ] ? [ "jwtToken" ] ? . ToString ( ) ;
334+
335+ parts = jwtToken . Split ( '.' ) ;
336+ if ( parts . Length != 3 )
337+ {
338+ Console . WriteLine ( "Invalid JWT" ) ;
339+ }
340+
341+ payload = JObject . Parse ( Base64UrlDecode ( parts [ 1 ] ) ) ;
342+ return payload ;
343+ }
344+
295345 [ Obsolete ( "Use GetUserDetails instead." ) ]
296346 public string GetEmail ( )
297347 {
You can’t perform that action at this time.
0 commit comments