Example #1
0
        protected IShareFileClient GetShareFileClient()
        {
            try
            {
                using (var fileStream = System.IO.File.OpenRead("TestConfig.json"))
                using (var streamReader = new StreamReader(fileStream))
                {
                    var info = streamReader.ReadToEnd();
                    var userInfo = JsonConvert.DeserializeObject<UserInfo>(info);

                    var sfClient = new ShareFileClient(userInfo.GetBaseUri().ToString());

                    lock (oauthTokenLock)
                    {
                        if (token == null)
                        {
                            var oauthService = new OAuthService(sfClient, userInfo.ClientId, userInfo.ClientSecret);
                            token = oauthService.GetPasswordGrantRequestQuery(userInfo.Email, userInfo.Password, userInfo.Subdomain, userInfo.Domain).Execute();
                        }
                    }

                    sfClient.BaseUri = token.GetUri();
                    sfClient.AddOAuthCredentials(token);
                    return sfClient;
                }
            }
            catch (Exception exception)
            {
                Assert.Inconclusive(string.Format("No UserInfo found in TestConfig.json. Exception: {0}", exception));
                throw;
            }
        }
Example #2
0
 public FormQuery<OAuthToken> GetRefreshOAuthTokenQuery(OAuthToken token)
 {
     return CreateOAuthTokenRequestQuery(token.ApplicationControlPlane,
         new Dictionary<string, string>
         {
             {"client_id", ClientId},
             {"client_secret", ClientSecret},
             {"refresh_token", token.RefreshToken},
             {"grant_type", "refresh_token"}
         }, token.Subdomain);
 }
 internal static IOAuthResponse ToOAuthResponse(this Dictionary<string, string> value)
 {
     IOAuthResponse response;
     
     if (value.ContainsKey("code"))
     {
         response = new OAuthAuthorizationCode();
     }
     else if (value.ContainsKey("access_token"))
     {
         response = new OAuthToken();
     }
     else if (value.ContainsKey("error"))
     {
         response = new OAuthError();
     }
     else response = new OAuthResponseBase();
     
     response.Fill(value);
     return response;
 }
 public OAuth2Credential(OAuthToken token)
     : base ("", token.AccessToken)
 {
     OAuthToken = token;
 }
Example #5
0
 public Task<OAuthToken> RefreshOAuthTokenAsync(OAuthToken token)
 {
     return RequestOAuthTokenAsync(GetRefreshOAuthTokenQuery(token));
 }