diff --git a/Thirdweb.Console/Program.cs b/Thirdweb.Console/Program.cs index ac5b856..a9737bc 100644 --- a/Thirdweb.Console/Program.cs +++ b/Thirdweb.Console/Program.cs @@ -455,7 +455,7 @@ #region InAppWallet - OAuth -// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Steam); +// var inAppWalletOAuth = await InAppWallet.Create(client: client, authProvider: AuthProvider.Github); // if (!await inAppWalletOAuth.IsConnected()) // { // _ = await inAppWalletOAuth.LoginWithOauth( @@ -472,6 +472,9 @@ // var inAppWalletOAuthAddress = await inAppWalletOAuth.GetAddress(); // Console.WriteLine($"InAppWallet OAuth address: {inAppWalletOAuthAddress}"); +// var inAppWalletAuthDetails = inAppWalletOAuth.GetUserAuthDetails(); +// Console.WriteLine($"InAppWallet OAuth auth details: {JsonConvert.SerializeObject(inAppWalletAuthDetails, Formatting.Indented)}"); + #endregion #region Smart Wallet - Gasless Transaction diff --git a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs index 376cf37..8bdcb53 100644 --- a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs @@ -5,6 +5,7 @@ using Nethereum.Signer; using Nethereum.Signer.EIP712; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Thirdweb.EWS; namespace Thirdweb; @@ -292,6 +293,55 @@ public async Task GetUserDetails() return await GetUserStatus(this.HttpClient).ConfigureAwait(false); } + /// + /// Gets the user auth details from the corresponding auth provider. + /// + /// The user auth details as a JObject + public JObject GetUserAuthDetails() + { + var authToken = this.EmbeddedWallet.GetSessionData()?.AuthToken; + if (string.IsNullOrEmpty(authToken)) + { + throw new InvalidOperationException("Cannot get user auth details without an active session."); + } + + var parts = authToken.Split('.'); + if (parts.Length != 3) + { + Console.WriteLine("Invalid JWT"); + } + + static string Base64UrlDecode(string input) + { + var paddedInput = input.Replace('-', '+').Replace('_', '/'); + switch (paddedInput.Length % 4) + { + case 2: + paddedInput += "=="; + break; + case 3: + paddedInput += "="; + break; + default: + break; + } + var decodedBytes = Convert.FromBase64String(paddedInput); + return Encoding.UTF8.GetString(decodedBytes); + } + + var payload = JObject.Parse(Base64UrlDecode(parts[1])); + var jwtToken = payload["storedToken"]?["jwtToken"]?.ToString(); + + parts = jwtToken.Split('.'); + if (parts.Length != 3) + { + Console.WriteLine("Invalid JWT"); + } + + payload = JObject.Parse(Base64UrlDecode(parts[1])); + return payload; + } + [Obsolete("Use GetUserDetails instead.")] public string GetEmail() {