This repository was archived by the owner on Jun 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDeveloperId.cs
More file actions
76 lines (61 loc) · 2.39 KB
/
Copy pathDeveloperId.cs
File metadata and controls
76 lines (61 loc) · 2.39 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
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation and Contributors
// Licensed under the MIT license.
using Microsoft.Windows.DevHome.SDK;
using Octokit;
namespace GitHubExtension.DeveloperId;
public class DeveloperId : IDeveloperId
{
public string LoginId { get; private set; }
public string DisplayName { get; private set; }
public string Email { get; private set; }
public string Url { get; private set; }
public DateTime CredentialExpiryTime { get; set; }
public GitHubClient GitHubClient { get; private set; }
public DeveloperId()
{
LoginId = string.Empty;
DisplayName = string.Empty;
Email = string.Empty;
Url = string.Empty;
GitHubClient = new (new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME));
}
public DeveloperId(string loginId, string displayName, string email, string url, GitHubClient gitHubClient)
{
LoginId = loginId;
DisplayName = displayName;
Email = email;
Url = url;
GitHubClient = gitHubClient;
}
~DeveloperId()
{
LoginId = string.Empty;
DisplayName = string.Empty;
Email = string.Empty;
Url = string.Empty;
return;
}
// IDeveloperIdInternal interface.
public Windows.Security.Credentials.PasswordCredential GetCredential(bool refreshIfExpired = false)
{
if (refreshIfExpired && (CredentialExpiryTime < DateTime.Now))
{
return RefreshDeveloperId();
}
var credential = DeveloperIdProvider.GetInstance().GetCredentials(this) ?? throw new InvalidOperationException("Invalid credential present for valid DeveloperId");
return credential;
}
public Windows.Security.Credentials.PasswordCredential RefreshDeveloperId()
{
// Setting to MaxValue, since GitHub doesn't forcibly expire tokens currently.
CredentialExpiryTime = DateTime.MaxValue;
DeveloperIdProvider.GetInstance().RefreshDeveloperId(this);
var credential = DeveloperIdProvider.GetInstance().GetCredentials(this) ?? throw new InvalidOperationException("Invalid credential present for valid DeveloperId");
GitHubClient.Credentials = new (credential.Password);
return credential;
}
public Uri GetHostAddress()
{
return GitHubClient.BaseAddress;
}
}