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 455
455
456
456
#region InAppWallet - OAuth
457
457
458
- // var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Steam );
458
+ // var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Github );
459
459
// if (!await inAppWalletOAuth.IsConnected())
460
460
// {
461
461
// _ = await inAppWalletOAuth.LoginWithOauth(
472
472
// var inAppWalletOAuthAddress = await inAppWalletOAuth.GetAddress();
473
473
// Console.WriteLine($"InAppWallet OAuth address: {inAppWalletOAuthAddress}");
474
474
475
+ // var inAppWalletAuthDetails = inAppWalletOAuth.GetUserAuthDetails();
476
+ // Console.WriteLine($"InAppWallet OAuth auth details: {JsonConvert.SerializeObject(inAppWalletAuthDetails, Formatting.Indented)}");
477
+
475
478
#endregion
476
479
477
480
#region Smart Wallet - Gasless Transaction
Original file line number Diff line number Diff line change 5
5
using Nethereum . Signer ;
6
6
using Nethereum . Signer . EIP712 ;
7
7
using Newtonsoft . Json ;
8
+ using Newtonsoft . Json . Linq ;
8
9
using Thirdweb . EWS ;
9
10
10
11
namespace Thirdweb ;
@@ -292,6 +293,55 @@ public async Task<UserStatusResponse> GetUserDetails()
292
293
return await GetUserStatus ( this . HttpClient ) . ConfigureAwait ( false ) ;
293
294
}
294
295
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
+
295
345
[ Obsolete ( "Use GetUserDetails instead." ) ]
296
346
public string GetEmail ( )
297
347
{
You can’t perform that action at this time.
0 commit comments