forked from DropNet/DropNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.Async.cs
More file actions
80 lines (74 loc) · 3.64 KB
/
Copy pathUser.Async.cs
File metadata and controls
80 lines (74 loc) · 3.64 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
using DropNet.Models;
using RestSharp;
using System;
using DropNet.Authenticators;
using DropNet.Exceptions;
namespace DropNet
{
public partial class DropNetClient
{
/// <summary>
/// Gets a token from the almightly dropbox.com (Token cant be used until authorized!)
/// </summary>
public void GetTokenAsync(Action<UserLogin> success, Action<DropboxException> failure)
{
var request = _requestHelper.CreateTokenRequest();
ExecuteAsync(ApiType.Base, request, response =>
{
var userLogin = GetUserLoginFromParams(response.Content);
UserLogin = userLogin;
success(userLogin);
}, failure);
}
/// <summary>
/// Converts a request token into an Access token after the user has authorized access via dropbox.com
/// </summary>
/// <param name="success"></param>
/// <param name="failure"></param>
public void GetAccessTokenAsync(Action<UserLogin> success, Action<DropboxException> failure)
{
var request = _requestHelper.CreateAccessTokenRequest();
ExecuteAsync(ApiType.Base, request, response =>
{
var userLogin = GetUserLoginFromParams(response.Content);
UserLogin = userLogin;
success(userLogin);
}, failure);
}
/// <summary>
/// Acquire an OAuth2 bearer token once the user has authorized the app. This endpoint only applies to apps using the AuthorizationFlow.Code flow.
/// </summary>
/// <param name="success">Action to perform with the OAuth2 access token</param>
/// <param name="failure"></param>
/// <param name="code">The authorization code provided by Dropbox when the user was redirected back to your site.</param>
/// <param name="redirectUri">The redirect Uri for your site. This is only used to validate that it matches the original /oauth2/authorize; the user will not be redirected again.</param>
public void GetAccessTokenAsync(Action<UserLogin> success, Action<DropboxException> failure, string code, string redirectUri)
{
RestRequest request = _requestHelper.CreateOAuth2AccessTokenRequest(code, redirectUri, _apiKey, _appsecret);
ExecuteAsync<OAuth2AccessToken>(ApiType.Base, request, response =>
{
var userLogin = new UserLogin { Token = response.Access_Token };
UserLogin = userLogin;
success(userLogin);
}, failure);
}
/// <summary>
/// Gets AccountInfo
/// </summary>
/// <param name="success"></param>
/// <param name="failure"></param>
public void AccountInfoAsync(Action<AccountInfo> success, Action<DropboxException> failure)
{
//This has to be here as Dropbox change their base URL between calls
var request = _requestHelper.CreateAccountInfoRequest();
ExecuteAsync(ApiType.Base, request, success, failure);
}
[Obsolete("No longer supported by Dropbox")]
public void CreateAccountAsync(string email, string firstName, string lastName, string password, Action<RestResponse> success, Action<DropboxException> failure)
{
//This has to be here as Dropbox change their base URL between calls
var request = _requestHelper.CreateNewAccountRequest(_apiKey, email, firstName, lastName, password);
ExecuteAsync(ApiType.Base, request, success, failure);
}
}
}