Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/MauiSherpa.Core/Services/AppleDownloadAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,15 @@ public async Task<bool> RequestSmsCodeAsync(TwoFactorMethod phone)

try
{
var serviceKey = await GetServiceKeyAsync();
var serviceKey = _pendingServiceKey ?? await GetServiceKeyAsync();
if (serviceKey == null) return false;

var request = new HttpRequestMessage(HttpMethod.Put, $"{AuthUrl}/verify/phone");
request.Headers.Add("X-Apple-Widget-Key", serviceKey);
if (_pendingSessionId != null)
request.Headers.Add("X-Apple-ID-Session-Id", _pendingSessionId);
if (_pendingScnt != null)
request.Headers.Add("scnt", _pendingScnt);
request.Content = new StringContent(
JsonSerializer.Serialize(new
{
Expand All @@ -298,6 +302,7 @@ public async Task<bool> RequestSmsCodeAsync(TwoFactorMethod phone)
Encoding.UTF8, "application/json");

var response = await _httpClient.SendAsync(request);
_logger.LogInformation($"SMS code request response: {(int)response.StatusCode} {response.StatusCode}");
return response.IsSuccessStatusCode;
}
catch (Exception ex)
Expand Down
24 changes: 22 additions & 2 deletions src/MauiSherpa/Pages/Modals/XcodeDownloadAuthModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@using MauiSherpa.Pages.Forms
@inject HybridFormBridgeHolder BridgeHolder
@inject XcodeManagementViewModel ViewModel
@inject IAppleDownloadAuthService AuthService
@implements IDisposable

@{
Expand Down Expand Up @@ -68,11 +69,11 @@
}
</p>

@if (twoFactorOptions?.TrustedPhoneNumbers.Count > 1)
@if (twoFactorOptions?.TrustedPhoneNumbers.Count > 0)
{
<div class="form-group">
<label>Verification method</label>
<select @bind="selectedPhoneIndex" @bind:after="OnFieldChanged" disabled="@isAuthenticating">
<select @bind="selectedPhoneIndex" @bind:after="OnPhoneSelectionChanged" disabled="@isAuthenticating">
@if (twoFactorOptions.CanUseTrustedDevice)
{
<option value="-1">Trusted Device</option>
Expand Down Expand Up @@ -149,6 +150,21 @@

private void OnFieldChanged() => UpdateWizardState();

private async Task OnPhoneSelectionChanged()
{
UpdateWizardState();
await RequestSmsForSelectedPhone();
}

private async Task RequestSmsForSelectedPhone()
{
if (selectedPhoneIndex >= 0 && twoFactorOptions?.TrustedPhoneNumbers.Count > selectedPhoneIndex)
{
var phone = twoFactorOptions.TrustedPhoneNumbers[selectedPhoneIndex];
await AuthService.RequestSmsCodeAsync(phone);
}
}

private void UpdateWizardState()
{
var bridge = BridgeHolder.Current;
Expand Down Expand Up @@ -211,6 +227,10 @@
&& twoFactorOptions.TrustedPhoneNumbers.Count > 0
? 0
: -1;

// If SMS was auto-selected, request the code be sent
if (selectedPhoneIndex >= 0)
await RequestSmsForSelectedPhone();
}
else
{
Expand Down
Loading