forked from DropNet/DropNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.Sync.cs
More file actions
72 lines (65 loc) · 2.76 KB
/
Copy pathUser.Sync.cs
File metadata and controls
72 lines (65 loc) · 2.76 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
#if !WINDOWS_PHONE
using DropNet.Models;
using RestSharp;
using DropNet.Authenticators;
using System;
namespace DropNet
{
public partial class DropNetClient
{
/// <summary>
/// Shorthand method to get an OAuth1 token from Dropbox and build the Url to authorize it.
/// </summary>
/// <returns></returns>
public string GetTokenAndBuildUrl(string callback = null)
{
GetToken();
return BuildAuthorizeUrl(callback);
}
/// <summary>
/// Provisions an OAuth1 token from the almightly dropbox.com (Token cant be used until authorized!)
/// </summary>
/// <returns></returns>
public UserLogin GetToken()
{
var request = _requestHelper.CreateTokenRequest();
var response = Execute(ApiType.Base, request);
var userLogin = GetUserLoginFromParams(response.Content);
UserLogin = userLogin;
return userLogin;
}
/// <summary>
/// Authorizes the previously-requested OAuth1 token
/// </summary>
/// <returns></returns>
public UserLogin GetAccessToken()
{
var request = _requestHelper.CreateAccessTokenRequest();
var response = Execute(ApiType.Base, request);
var userLogin = GetUserLoginFromParams(response.Content);
//This is the new Access token we have
UserLogin = userLogin;
return userLogin;
}
/// <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="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>
/// <returns>An OAuth2 bearer token.</returns>
public UserLogin GetAccessToken(string code, string redirectUri)
{
RestRequest request = _requestHelper.CreateOAuth2AccessTokenRequest(code, redirectUri, _apiKey, _appsecret);
var response = Execute<OAuth2AccessToken>(ApiType.Base, request);
var userLogin = new UserLogin { Token = response.Access_Token };
UserLogin = userLogin;
return userLogin;
}
public AccountInfo AccountInfo()
{
var request = _requestHelper.CreateAccountInfoRequest();
return Execute<AccountInfo>(ApiType.Base, request);
}
}
}
#endif