Skip to content

Commit 2667928

Browse files
authored
feat: auto login (#5636)
1 parent 24cb1f8 commit 2667928

File tree

44 files changed

+221
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+221
-33
lines changed

Explorer/Assets/DCL/Infrastructure/Global/Dynamic/BootstrapAnalyticsDecorator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ public void InitializeFeaturesRegistry()
178178
core.InitializeFeaturesRegistry();
179179
}
180180

181-
public async UniTask UserInitializationAsync(DynamicWorldContainer dynamicWorldContainer, GlobalWorld globalWorld, Entity playerEntity, CancellationToken ct)
181+
public async UniTask UserInitializationAsync(DynamicWorldContainer dynamicWorldContainer,
182+
BootstrapContainer bootstrapContainer,
183+
GlobalWorld globalWorld, Entity playerEntity, CancellationToken ct)
182184
{
183-
await core.UserInitializationAsync(dynamicWorldContainer, globalWorld, playerEntity, ct);
185+
await core.UserInitializationAsync(dynamicWorldContainer, bootstrapContainer, globalWorld, playerEntity, ct);
184186

185187
analytics.Track(General.INITIAL_LOADING, new JsonObject
186188
{

Explorer/Assets/DCL/Infrastructure/Global/Dynamic/BootstrapContainer.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class BootstrapContainer : DCLGlobalContainer<BootstrapSettings>
4848
public IWeb3IdentityCache? IdentityCache { get; private set; }
4949
public IVerifiedEthereumApi? VerifiedEthereumApi { get; private set; }
5050
public IWeb3VerifiedAuthenticator? Web3Authenticator { get; private set; }
51+
public IWeb3Authenticator? AutoLoginAuthenticator { get; private set; }
5152
public IAnalyticsController? Analytics { get; private set; }
5253
public DebugSettings.DebugSettings DebugSettings { get; private set; }
5354
public VolumeBus VolumeBus { get; private set; }
@@ -110,7 +111,7 @@ await bootstrapContainer.InitializeContainerAsync<BootstrapContainer, BootstrapS
110111
container.reportHandlingSettings = ProvideReportHandlingSettingsAsync(container.settings);
111112

112113
(container.Bootstrap, container.Analytics) = CreateBootstrapperAsync(debugSettings, applicationParametersParser, splashScreen, realmUrls, diskCache, partialsDiskCache, container, webRequestsContainer, container.settings, realmLaunchSettings, world, container.settings.BuildData, dclVersion, ct);
113-
(container.VerifiedEthereumApi, container.Web3Authenticator) = CreateWeb3Dependencies(sceneLoaderSettings, web3AccountFactory, identityCache, browser, container, decentralandUrlsSource, decentralandEnvironment, applicationParametersParser);
114+
(container.VerifiedEthereumApi, container.Web3Authenticator, container.AutoLoginAuthenticator) = CreateWeb3Dependencies(sceneLoaderSettings, web3AccountFactory, identityCache, browser, container, decentralandUrlsSource, decentralandEnvironment, applicationParametersParser, webRequestsContainer);
114115

115116
if (container.enableAnalytics)
116117
{
@@ -202,7 +203,7 @@ private static IAnalyticsService CreateSegmentAnalyticsOrFallbackToDebug(Analyti
202203
return new DebugAnalyticsService();
203204
}
204205

205-
private static (IVerifiedEthereumApi web3VerifiedAuthenticator, IWeb3VerifiedAuthenticator web3Authenticator)
206+
private static (IVerifiedEthereumApi web3VerifiedAuthenticator, IWeb3VerifiedAuthenticator web3Authenticator, IWeb3Authenticator autoLoginAuthenticator)
206207
CreateWeb3Dependencies(
207208
DynamicSceneLoaderSettings sceneLoaderSettings,
208209
IWeb3AccountFactory web3AccountFactory,
@@ -211,10 +212,9 @@ private static (IVerifiedEthereumApi web3VerifiedAuthenticator, IWeb3VerifiedAut
211212
BootstrapContainer container,
212213
IDecentralandUrlsSource decentralandUrlsSource,
213214
DecentralandEnvironment dclEnvironment,
214-
IAppArgs appArgs)
215+
IAppArgs appArgs,
216+
WebRequestsContainer webRequestsContainer)
215217
{
216-
217-
218218
var dappWeb3Authenticator = new DappWeb3Authenticator(
219219
webBrowser,
220220
URLAddress.FromString(decentralandUrlsSource.Url(DecentralandUrl.ApiAuth)),
@@ -231,10 +231,19 @@ private static (IVerifiedEthereumApi web3VerifiedAuthenticator, IWeb3VerifiedAut
231231

232232
IWeb3VerifiedAuthenticator coreWeb3Authenticator = new ProxyVerifiedWeb3Authenticator(dappWeb3Authenticator, identityCache);
233233

234+
IWeb3Authenticator autoLoginAuthenticator = new TokenFileAuthenticator(
235+
URLAddress.FromString(decentralandUrlsSource.Url(DecentralandUrl.ApiAuth)),
236+
webRequestsContainer.WebRequestController, web3AccountFactory);
237+
238+
autoLoginAuthenticator = new ProxyWeb3Authenticator(autoLoginAuthenticator, identityCache);
239+
234240
if (container.enableAnalytics)
235-
coreWeb3Authenticator = new IdentityAnalyticsDecorator(coreWeb3Authenticator, container.Analytics!);
241+
{
242+
coreWeb3Authenticator = new AnalyticsDecoratorVerifiedAuthenticator(coreWeb3Authenticator, container.Analytics!);
243+
autoLoginAuthenticator = new AnalyticsDecoratorAuthenticator(autoLoginAuthenticator, container.Analytics!);
244+
}
236245

237-
return (dappWeb3Authenticator, coreWeb3Authenticator);
246+
return (dappWeb3Authenticator, coreWeb3Authenticator, autoLoginAuthenticator);
238247
}
239248

240249
private static ReportsHandlingSettings ProvideReportHandlingSettingsAsync(BootstrapSettings settings)

Explorer/Assets/DCL/Infrastructure/Global/Dynamic/Bootstraper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using DCL.UserInAppInitializationFlow;
2020
using DCL.Utilities;
2121
using DCL.Utilities.Extensions;
22+
using DCL.Web3.Authenticators;
2223
using DCL.Web3.Identities;
2324
using DCL.WebRequests.Analytics;
2425
using ECS.StreamableLoading.Cache.Disk;
@@ -287,10 +288,16 @@ public void ApplyFeatureFlagConfigs(FeatureFlagsConfiguration featureFlagsConfig
287288
}
288289

289290
public async UniTask UserInitializationAsync(DynamicWorldContainer dynamicWorldContainer,
291+
BootstrapContainer bootstrapContainer,
290292
GlobalWorld globalWorld, Entity playerEntity, CancellationToken ct)
291293
{
292294
splashScreen.Show();
293295

296+
try { await bootstrapContainer.AutoLoginAuthenticator!.LoginAsync(ct); }
297+
// Exceptions on auto-login should not block the application bootstrap
298+
catch (AutoLoginTokenNotFoundException) { }
299+
catch (Exception e) { ReportHub.LogException(e, ReportCategory.AUTHENTICATION); }
300+
294301
await dynamicWorldContainer.UserInAppInAppInitializationFlow.ExecuteAsync(
295302
new UserInAppInitializationFlowParameters
296303
(

Explorer/Assets/DCL/Infrastructure/Global/Dynamic/IBootstrap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ UniTask<bool> InitializePluginsAsync(StaticContainer staticContainer, DynamicWor
5757
GlobalWorld CreateGlobalWorld(BootstrapContainer bootstrapContainer, StaticContainer staticContainer, DynamicWorldContainer dynamicWorldContainer,
5858
UIDocument debugUiRoot, Entity playerEntity);
5959

60-
UniTask UserInitializationAsync(DynamicWorldContainer dynamicWorldContainer, GlobalWorld globalWorld, Entity playerEntity, CancellationToken ct);
60+
UniTask UserInitializationAsync(DynamicWorldContainer dynamicWorldContainer, BootstrapContainer bootstrapContainer, GlobalWorld globalWorld, Entity playerEntity, CancellationToken ct);
6161

6262
UniTask LoadStartingRealmAsync(DynamicWorldContainer dynamicWorldContainer, CancellationToken ct);
6363

Explorer/Assets/DCL/Infrastructure/Global/Dynamic/MainSceneLoader.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@
2121
using DCL.Multiplayer.HealthChecks;
2222
using DCL.Multiplayer.HealthChecks.Struct;
2323
using DCL.Optimization.PerformanceBudgeting;
24+
using DCL.PerformanceAndDiagnostics.Analytics;
2425
using DCL.PluginSystem;
2526
using DCL.PluginSystem.Global;
2627
using DCL.Prefs;
2728
using DCL.SceneLoadingScreens.SplashScreen;
29+
using DCL.Settings.ModuleControllers;
2830
using DCL.Utilities;
2931
using DCL.Utilities.Extensions;
32+
using DCL.Utility;
33+
using DCL.Utility.Types;
3034
using DCL.Web3.Accounts.Factory;
3135
using DCL.Web3.Identities;
3236
using DCL.WebRequests;
3337
using DCL.WebRequests.Analytics;
38+
using DCL.WebRequests.ChromeDevtool;
3439
using ECS.StreamableLoading.Cache.Disk;
3540
using ECS.StreamableLoading.Cache.Disk.CleanUp;
3641
using ECS.StreamableLoading.Cache.Disk.Lock;
@@ -53,8 +58,6 @@
5358
using DCL.Utility.Types;
5459
using System.Collections.Generic;
5560
using TMPro;
56-
#if UNITY_EDITOR
57-
#endif
5861
using UnityEngine;
5962
using UnityEngine.AddressableAssets;
6063
using Utility;
@@ -152,6 +155,7 @@ private async UniTask InitializeFlowAsync(CancellationToken ct)
152155
// Memory limit
153156
bool hasSimulatedMemory = applicationParametersParser.TryGetValue(AppArgsFlags.SIMULATE_MEMORY, out string simulatedMemory);
154157
int systemMemory = hasSimulatedMemory ? int.Parse(simulatedMemory) : SystemInfo.systemMemorySize;
158+
155159
ISystemMemoryCap memoryCap = hasSimulatedMemory
156160
? new SystemMemoryCap(systemMemory)
157161
: new SystemMemoryCap();
@@ -279,7 +283,7 @@ await bootstrap.InitializeFeatureFlagsAsync(bootstrapContainer.IdentityCache!.Id
279283

280284
await bootstrap.LoadStartingRealmAsync(dynamicWorldContainer!, ct);
281285

282-
await bootstrap.UserInitializationAsync(dynamicWorldContainer!, globalWorld, playerEntity, ct);
286+
await bootstrap.UserInitializationAsync(dynamicWorldContainer!, bootstrapContainer, globalWorld, playerEntity, ct);
283287

284288
//This is done to release the memory usage of the splash screen logo animation sprites
285289
//The logo is used only at first launch, so we can safely release it after the game is loaded
@@ -317,6 +321,7 @@ private async UniTask VerifyMinimumHardwareRequirementMetAsync(IAppArgs applicat
317321
new PlatformDriveInfoProvider());
318322

319323
bool hasMinimumSpecs = minimumSpecsGuard.HasMinimumSpecs();
324+
320325
if (!hasMinimumSpecs)
321326
{
322327
DCLPlayerPrefs.SetInt(DCLPrefKeys.SETTINGS_GRAPHICS_QUALITY, GraphicsQualitySettingsController.MIN_SPECS_GRAPHICS_QUALITY_LEVEL, true);
@@ -326,22 +331,19 @@ private async UniTask VerifyMinimumHardwareRequirementMetAsync(IAppArgs applicat
326331
bool userWantsToSkip = DCLPlayerPrefs.GetBool(DCLPrefKeys.DONT_SHOW_MIN_SPECS_SCREEN);
327332
bool forceShow = applicationParametersParser.HasFlag(AppArgsFlags.FORCE_MINIMUM_SPECS_SCREEN);
328333

329-
bootstrapContainer.DiagnosticsContainer.AddSentryScopeConfigurator(scope =>
330-
{
331-
bootstrapContainer.DiagnosticsContainer.Sentry!.AddMeetMinimumRequirements(scope, hasMinimumSpecs);
332-
});
334+
bootstrapContainer.DiagnosticsContainer.AddSentryScopeConfigurator(scope => { bootstrapContainer.DiagnosticsContainer.Sentry!.AddMeetMinimumRequirements(scope, hasMinimumSpecs); });
333335

334336
bool shouldShowScreen = forceShow || (!userWantsToSkip && !hasMinimumSpecs);
335337

336338
if (!shouldShowScreen)
337339
return;
338340

339341
var minimumRequirementsPrefab = await bootstrapContainer!
340-
.AssetsProvisioner!
341-
.ProvideMainAssetAsync(dynamicSettings.MinimumSpecsScreenPrefab, ct);
342+
.AssetsProvisioner!
343+
.ProvideMainAssetAsync(dynamicSettings.MinimumSpecsScreenPrefab, ct);
342344

343345
ControllerBase<MinimumSpecsScreenView, ControllerNoData>.ViewFactoryMethod viewFactory = MinimumSpecsScreenController
344-
.CreateLazily(minimumRequirementsPrefab.Value.GetComponent<MinimumSpecsScreenView>(), null);
346+
.CreateLazily(minimumRequirementsPrefab.Value.GetComponent<MinimumSpecsScreenView>(), null);
345347

346348
var minimumSpecsResults = minimumSpecsGuard.Results;
347349
var minimumSpecsScreenController = new MinimumSpecsScreenController(viewFactory, webBrowser, analytics, minimumSpecsResults);
@@ -593,9 +595,7 @@ public void Dispose()
593595
[Serializable]
594596
public class SplashScreenRef : ComponentReference<SplashScreen>
595597
{
596-
public SplashScreenRef(string guid) : base(guid)
597-
{
598-
}
598+
public SplashScreenRef(string guid) : base(guid) { }
599599
}
600600
}
601601
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using Cysharp.Threading.Tasks;
1+
using Cysharp.Threading.Tasks;
22
using DCL.Web3.Authenticators;
33
using DCL.Web3.Identities;
44
using System.Threading;
55

66
namespace DCL.PerformanceAndDiagnostics.Analytics
77
{
8-
public class IdentityAnalyticsDecorator : IWeb3VerifiedAuthenticator
8+
public class AnalyticsDecoratorAuthenticator : IWeb3Authenticator
99
{
10-
private readonly IWeb3VerifiedAuthenticator core;
10+
private readonly IWeb3Authenticator core;
1111
private readonly IAnalyticsController analytics;
1212

13-
public IdentityAnalyticsDecorator(IWeb3VerifiedAuthenticator core, IAnalyticsController analytics)
13+
public AnalyticsDecoratorAuthenticator(IWeb3Authenticator core, IAnalyticsController analytics)
1414
{
1515
this.core = core;
1616
this.analytics = analytics;
@@ -30,8 +30,5 @@ public async UniTask<IWeb3Identity> LoginAsync(CancellationToken ct)
3030

3131
public async UniTask LogoutAsync(CancellationToken cancellationToken) =>
3232
await core.LogoutAsync(cancellationToken);
33-
34-
public void SetVerificationListener(IWeb3VerifiedAuthenticator.VerificationDelegate callback) =>
35-
core.SetVerificationListener(callback);
3633
}
3734
}

Explorer/Assets/DCL/PerformanceAndDiagnostics/Analytics/DecoratorBased/AnalyticsDecoratorAuthenticator.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using DCL.Web3.Authenticators;
2+
3+
namespace DCL.PerformanceAndDiagnostics.Analytics
4+
{
5+
public class AnalyticsDecoratorVerifiedAuthenticator : AnalyticsDecoratorAuthenticator, IWeb3VerifiedAuthenticator
6+
{
7+
private readonly IWeb3VerifiedAuthenticator core;
8+
9+
public AnalyticsDecoratorVerifiedAuthenticator(IWeb3VerifiedAuthenticator core, IAnalyticsController analytics)
10+
: base(core, analytics)
11+
{
12+
this.core = core;
13+
}
14+
15+
public void SetVerificationListener(IWeb3VerifiedAuthenticator.VerificationDelegate? callback) =>
16+
core.SetVerificationListener(callback);
17+
}
18+
}

Explorer/Assets/DCL/PluginSystem/DCL.Plugins.asmdef

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@
134134
"GUID:37a4d7b6b1ae9644b95acf1816d50355",
135135
"GUID:1087662aaf1c5462baa91fb9484296fd",
136136
"GUID:5556c2cd8a339d54ba194f39bbd30d73",
137-
"GUID:e4725e82149f9428aa30a172156263ce"
137+
"GUID:e4725e82149f9428aa30a172156263ce",
138+
"GUID:29f99fa49221a4df7aecb5cd50457e5f",
139+
"GUID:92920c790fc0443e9a7ec2f7d1e5308f"
138140
],
139141
"includePlatforms": [],
140142
"excludePlatforms": [],

0 commit comments

Comments
 (0)