@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
using System ;
using System.Net ;
using System.Threading.Tasks ;
using System.Windows.Input ;
using Bit.App.Abstractions ;
@ -27,6 +28,7 @@ namespace Bit.App.Pages
@@ -27,6 +28,7 @@ namespace Bit.App.Pages
private readonly IPlatformUtilsService _ platformUtilsService ;
private readonly IStateService _ stateService ;
private readonly ILogger _l ogger ;
private readonly IOrganizationService _ organizationService ;
private string _ orgIdentifier ;
@ -42,6 +44,7 @@ namespace Bit.App.Pages
@@ -42,6 +44,7 @@ namespace Bit.App.Pages
_ platformUtilsService = ServiceContainer . Resolve < IPlatformUtilsService > ( "platformUtilsService" ) ;
_ stateService = ServiceContainer . Resolve < IStateService > ( "stateService" ) ;
_l ogger = ServiceContainer . Resolve < ILogger > ( "logger" ) ;
_ organizationService = ServiceContainer . Resolve < IOrganizationService > ( ) ;
PageTitle = AppResources . Bitwarden ;
@ -63,9 +66,25 @@ namespace Bit.App.Pages
@@ -63,9 +66,25 @@ namespace Bit.App.Pages
public async Task InitAsync ( )
{
if ( string . IsNullOrWhiteSpace ( OrgIdentifier ) )
try
{
OrgIdentifier = await _ stateService . GetRememberedOrgIdentifierAsync ( ) ;
if ( await TryClaimedDomainLogin ( ) )
{
return ;
}
if ( string . IsNullOrWhiteSpace ( OrgIdentifier ) )
{
OrgIdentifier = await _ stateService . GetRememberedOrgIdentifierAsync ( ) ;
}
}
catch ( Exception ex )
{
_l ogger . Exception ( ex ) ;
}
finally
{
await _d eviceActionService . HideLoadingAsync ( ) ;
}
}
@ -207,5 +226,37 @@ namespace Bit.App.Pages
@@ -207,5 +226,37 @@ namespace Bit.App.Pages
AppResources . AnErrorHasOccurred ) ;
}
}
private async Task < bool > TryClaimedDomainLogin ( )
{
try
{
await _d eviceActionService . ShowLoadingAsync ( AppResources . Loading ) ;
var userEmail = await _ stateService . GetPreLoginEmailAsync ( ) ;
var claimedDomainOrgDetails = await _ organizationService . GetClaimedOrganizationDomainAsync ( userEmail ) ;
await _d eviceActionService . HideLoadingAsync ( ) ;
if ( claimedDomainOrgDetails = = null | | ! claimedDomainOrgDetails . SsoAvailable )
{
return false ;
}
if ( string . IsNullOrEmpty ( claimedDomainOrgDetails . OrganizationIdentifier ) )
{
await _ platformUtilsService . ShowDialogAsync ( AppResources . OrganizationSsoIdentifierRequired , AppResources . AnErrorHasOccurred ) ;
return false ;
}
OrgIdentifier = claimedDomainOrgDetails . OrganizationIdentifier ;
await LogInAsync ( ) ;
return true ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
return false ;
}
}
}