This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTwoFactorChallengeHandler.cs
More file actions
67 lines (58 loc) · 2.08 KB
/
Copy pathTwoFactorChallengeHandler.cs
File metadata and controls
67 lines (58 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.ComponentModel.Composition;
using System.Reactive.Linq;
using GitHub.ViewModels;
using Octokit;
using ReactiveUI;
using System.Threading.Tasks;
using GitHub.Api;
using GitHub.Extensions;
using GitHub.ViewModels.Dialog;
using Microsoft.VisualStudio.Threading;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;
namespace GitHub.Authentication
{
[Export(typeof(ITwoFactorChallengeHandler))]
[Export(typeof(IDelegatingTwoFactorChallengeHandler))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class TwoFactorChallengeHandler : ReactiveObject, IDelegatingTwoFactorChallengeHandler
{
[ImportingConstructor]
public TwoFactorChallengeHandler([Import(AllowDefault = true)] JoinableTaskContext joinableTaskContext)
{
JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext;
}
ILogin2FaViewModel twoFactorDialog;
public IViewModel CurrentViewModel
{
get { return twoFactorDialog; }
private set { this.RaiseAndSetIfChanged(ref twoFactorDialog, (ILogin2FaViewModel)value); }
}
public void SetViewModel(IViewModel vm)
{
CurrentViewModel = vm;
}
public async Task<TwoFactorChallengeResult> HandleTwoFactorException(TwoFactorAuthorizationException exception)
{
Guard.ArgumentNotNull(exception, nameof(exception));
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
var userError = new TwoFactorRequiredUserError(exception);
var result = await twoFactorDialog.Show(userError);
if (result != null)
{
return result;
}
else
{
throw exception;
}
}
public async Task ChallengeFailed(Exception exception)
{
await JoinableTaskContext.Factory.SwitchToMainThreadAsync();
twoFactorDialog.Cancel();
}
JoinableTaskContext JoinableTaskContext { get; }
}
}