public void SetUp() { var uri = OAuthRequestHandler.OAuthRequestUri; var factory = new TestWebRequestFactory(); factory.RegisterResultForUri(uri.AbsoluteUri, "null"); _request = factory.Create(uri); _stream = new MemoryStream(); _request.EndGetRequestStream(Arg.Any<IAsyncResult>()).Returns(c => _stream); _request.GetRequestStreamAsync().Returns(async c => (Stream)_stream); _handler = new OAuthRequestHandler(new ApiConfiguration("<<clientid>>", "<<clientsecret>>", "http://desktop/")); }
/// <summary> /// Get the OAuth tokens required to access the cloud based API (Delegate) /// </summary> /// <param name="code">The code received after the user has given the application permission to access their company files</param> /// <param name="onComplete">The action to call when the operation is complete</param> /// <param name="onError">The action to call when the operation has an error</param> public void GetTokens(string code, Action<HttpStatusCode, OAuthTokens> onComplete, Action<Uri, Exception> onError) { var handler = new OAuthRequestHandler(_configuration); var request = this.Factory.Create(OAuthRequestHandler.OAuthRequestUri); handler.GetOAuthTokens(request, code, onComplete, onError); }
/// <summary> /// Get the OAuth tokens required to access the cloud based API (Synchronous) /// </summary> /// <param name="code">The code received after the user has given the application permission to access their company files</param> /// <param name="cancellationToken"></param> /// <returns>The tokens that are required to access the user's company files</returns> async public Task<OAuthTokens> GetTokensAsync(string code, CancellationToken cancellationToken) { var handler = new OAuthRequestHandler(_configuration); var request = this.Factory.Create(OAuthRequestHandler.OAuthRequestUri); var tokens = await handler.GetOAuthTokensAsync(request, code, cancellationToken); return tokens.Item2; }
/// <summary> /// Renew the OAuth tokens required to access the cloud based API (Synchronous) /// </summary> /// <param name="oauthTokens">The tokens that are required to access the user's company files</param> /// <param name="cancellationToken"></param> /// <returns></returns> async public Task<OAuthTokens> RenewTokensAsync(OAuthTokens oauthTokens, CancellationToken cancellationToken) { var handler = new OAuthRequestHandler(_configuration); var request = this.Factory.Create(OAuthRequestHandler.OAuthRequestUri); var tokens = await handler.RenewOAuthTokensAsync(request, oauthTokens, cancellationToken); return tokens.Item2; }
public void RenewTokens(OAuthTokens oauthTokens, Action<HttpStatusCode, OAuthTokens> onComplete, Action<Uri, Exception> onError) { var handler = new OAuthRequestHandler(_configuration); var request = _factory.Create(OAuthRequestHandler.OAuthRequestUri); handler.RenewOAuthTokens(request, oauthTokens, onComplete, onError); }