This repository was archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathClient.User.cs
More file actions
119 lines (89 loc) · 3.68 KB
/
Copy pathClient.User.cs
File metadata and controls
119 lines (89 loc) · 3.68 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System.Threading;
using DropNetRT.HttpHelpers;
using DropNetRT.Models;
using System.Net.Http;
using System.Threading.Tasks;
namespace DropNetRT
{
public partial class DropNetClient
{
/// <summary>
/// Auth Step 1. Gets a Request Token which is required for the login request
/// </summary>
/// <returns></returns>
public async Task<UserLogin> GetRequestToken()
{
var requestUrl = MakeRequestString("1/oauth/request_token", ApiType.Base);
var request = new HttpRequest(HttpMethod.Get, requestUrl);
_oauthHandler.Authenticate(request);
var response = await _httpClient.SendAsync(request);
string responseBody = await response.Content.ReadAsStringAsync();
UserLogin = GetUserLoginFromParams(responseBody);
SetUserToken(UserLogin);
return UserLogin;
}
/// <summary>
/// Auth Step 3. Once a Request Token has been authorized convert it to an access token for API usage.
/// </summary>
/// <returns></returns>
public async Task<UserLogin> GetAccessToken()
{
var requestUrl = MakeRequestString("1/oauth/access_token", ApiType.Base);
var request = new HttpRequest(HttpMethod.Get, requestUrl);
_oauthHandler.Authenticate(request);
var response = await _httpClient.SendAsync(request);
string responseBody = await response.Content.ReadAsStringAsync();
UserLogin = GetUserLoginFromParams(responseBody);
SetUserToken(UserLogin);
return UserLogin;
}
/// <summary>
/// Gets the account info of the current logged in user
/// </summary>
/// <returns></returns>
public Task<AccountInfo> AccountInfo()
{
return AccountInfo(CancellationToken.None);
}
/// <summary>
/// Gets the account info of the current logged in user
/// </summary>
/// <returns></returns>
public async Task<AccountInfo> AccountInfo(CancellationToken cancellationToken)
{
var requestUrl = MakeRequestString("1/account/info", ApiType.Base);
var request = new HttpRequest(HttpMethod.Get, requestUrl);
var response = await SendAsync<AccountInfo>(request, cancellationToken);
return response;
}
/// <summary>
/// Gets the oauth2 token for current logged in user
/// </summary>
/// <returns></returns>
public Task<string> GetOAuth2Token()
{
return GetOAuth2Token(CancellationToken.None);
}
/// <summary>
/// Gets the oauth2 token for current logged in user
/// </summary>
/// <returns></returns>
public async Task<string> GetOAuth2Token(CancellationToken cancellationToken)
{
var requestUrl = MakeRequestString("1/oauth2/token_from_oauth1", ApiType.Base);
var request = new HttpRequest (HttpMethod.Post, requestUrl);
var response = await SendAsync<OAuth2TokenResponse>(request, cancellationToken);
return response.Token;
}
/// <summary>
/// Disables the access token used to authenticate the call.
/// This method works for OAuth 1 and OAuth 2 tokens.
/// </summary>
public async Task DisableAccessToken(CancellationToken cancellationToken)
{
var requestUrl = MakeRequestString("1/disable_access_token", ApiType.Base);
var request = new HttpRequest(HttpMethod.Post, requestUrl);
await SendAsync(request, cancellationToken);
}
}
}