Skip to content

Commit

Permalink
platform agnostic login link oauth + otp prevalid
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper committed Jun 25, 2024
1 parent 9487d1f commit ea3e781
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class AWS
private const string cognitoAppClientId = "2e02ha2ce6du13ldk8pai4h3d0";
private static readonly string cognitoIdentityPoolId = $"{awsRegion}:2ad7ab1e-f48b-48a6-adfa-ac1090689c26";
private static readonly string cognitoUserPoolId = $"{awsRegion}_UFwLcZIpq";
private static readonly string recoverySharePasswordLambdaFunctionName = "arn:aws:lambda:us-west-2:324457261097:function:recovery-share-password-GenerateRecoverySharePassw-bbE5ZbVAToil";
private static readonly string recoverySharePasswordLambdaFunctionName = $"arn:aws:lambda:{awsRegion}:324457261097:function:recovery-share-password-GenerateRecoverySharePassw-bbE5ZbVAToil";

internal static async Task SignUpCognitoUserAsync(string emailAddress, string userName, Type thirdwebHttpClientType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal abstract class ServerBase

internal abstract Task<(string authShare, string recoveryShare)> FetchAuthAndRecoverySharesAsync(string authToken);
internal abstract Task<string> FetchAuthShareAsync(string authToken);
internal abstract Task<string> FetchHeadlessOauthLoginLinkAsync(string authProvider);
internal abstract Task<string> FetchHeadlessOauthLoginLinkAsync(string authProvider, string platform);

internal abstract Task<bool> CheckIsEmailKmsOtpValidAsync(string userName, string otp);
internal abstract Task<bool> CheckIsEmailUserOtpValidAsync(string emailAddress, string otp);
Expand Down Expand Up @@ -177,13 +177,13 @@ private async Task<IdTokenResponse> FetchCognitoIdTokenAsync(string authToken)
}

// embedded-wallet/headless-oauth-login-link
internal override async Task<string> FetchHeadlessOauthLoginLinkAsync(string authProvider)
internal override async Task<string> FetchHeadlessOauthLoginLinkAsync(string authProvider, string platform)
{
var uri = MakeUri(
"/embedded-wallet/headless-oauth-login-link",
new Dictionary<string, string>
{
{ "platform", "unity" },
{ "platform", platform },
{ "authProvider", authProvider },
{ "baseUrl", "https://embedded-wallet.thirdweb.com" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public async Task<VerifyResult> VerifyOtpAsync(string emailAddress, string otp,
{
if (localStorage.Session.IsKmsWallet)
{
// if (!await server.CheckIsEmailKmsOtpValidAsync(emailAddress, otp))
// {
// throw new VerificationException("Invalid OTP", true);
// }
if (!await server.CheckIsEmailKmsOtpValidAsync(emailAddress, otp))
{
throw new VerificationException("Invalid OTP", true);
}
Server.VerifyResult result = await server.VerifyKmsOtpAsync(emailAddress, otp, localStorage.Session.Id).ConfigureAwait(false);
await localStorage.RemoveSessionAsync().ConfigureAwait(false);
return await PostAuthSetup(result, recoveryCode, null, "EmailOTP").ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public async Task<VerifyResult> SignInWithOauthAsync(string authProvider, string
return await PostAuthSetup(result, recoveryCode, null, authProvider).ConfigureAwait(false);
}

public async Task<string> FetchHeadlessOauthLoginLinkAsync(string authProvider)
public async Task<string> FetchHeadlessOauthLoginLinkAsync(string authProvider, string platform)
{
return await server.FetchHeadlessOauthLoginLinkAsync(authProvider).ConfigureAwait(false);
return await server.FetchHeadlessOauthLoginLinkAsync(authProvider, platform).ConfigureAwait(false);
}

public async Task<bool> IsRecoveryCodeNeededAsync(string authResultStr)
Expand Down
5 changes: 2 additions & 3 deletions Thirdweb/Thirdweb.Wallets/InAppWallet/InAppWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ public virtual async Task<string> LoginWithOauth(
throw new ArgumentNullException(nameof(mobileRedirectScheme), "Mobile redirect scheme cannot be null or empty on this platform.");
}

// TODO: Use this for login link when it's ready in backend
var platform = "unity";
var platform = _client.HttpClient?.Headers["x-sdk-platform"] ?? "dotnet";
var redirectUrl = isMobile ? mobileRedirectScheme : "http://localhost:8789/";
var loginUrl = await _embeddedWallet.FetchHeadlessOauthLoginLinkAsync(_authProvider);
var loginUrl = await _embeddedWallet.FetchHeadlessOauthLoginLinkAsync(_authProvider, platform);
loginUrl = $"{loginUrl}?platform={platform}&redirectUrl={redirectUrl}&developerClientId={_client.ClientId}&authOption={_authProvider}";

browser ??= new InAppWalletBrowser();
Expand Down

0 comments on commit ea3e781

Please sign in to comment.