public async Task<AccessToken> GetAccessTokenAsync(RequestToken requestToken, string verifier) { if (requestToken == null) throw new InvalidOperationException("Cannot get the Access token without a Request token."); if (verifier == null) throw new InvalidOperationException("Cannot get the Access token without a verifer"); if (string.IsNullOrWhiteSpace(verifier)) throw new Exception("There was no oauth_verifier parameter on the callback request."); var client = new RestClient(_apiBaseUrl) { Authenticator = OAuth1Authenticator.ForAccessToken(_consumerKey, _consumerSecret, requestToken.Value, requestToken.Secret, verifier) }; var request = new RestRequest(AccessTokenPath); var response = await client.ExecuteAsync(request); if (response.StatusCode == HttpStatusCode.OK) { var queryString = HttpUtility.ParseQueryString(response.Content); var accessToken = new AccessToken(queryString["oauth_token"], queryString["oauth_token_secret"]); return accessToken; } throw new Exception("An error occured: Status code: " + response.StatusCode, response.ErrorException); }
public string BuildAuthorizationRequestUrl(RequestToken requestToken, string callbackUrl) { var builder = new UriBuilder(_apiBaseUrl); builder.Path = builder.Path.TrimEnd('/') + "/" + PortalUserAuthorizePath.TrimStart('/'); builder.Query = string.Format("oauth_token={0}&oauth_callback={1}", requestToken.Value, callbackUrl); return builder.ToString(); }
public async Task<RequestToken> GetRequestTokenAsync(string callbackUrl) { var client = new RestClient(_apiBaseUrl) { Authenticator = OAuth1Authenticator.ForRequestToken(_consumerKey, _consumerSecret, callbackUrl) }; var request = new RestRequest(RequestTokenPath); var response = await client.ExecuteAsync(request); if (response.StatusCode == HttpStatusCode.OK) { var queryString = HttpUtility.ParseQueryString(response.Content); var requestToken = new RequestToken(queryString["oauth_token"], queryString["oauth_token_secret"]); return requestToken; } throw new Exception("An error occured: Status code: " + response.StatusCode, response.ErrorException); }
public async Task<AccessToken> GetAccessTokenAsync(RequestToken requestToken) { if (requestToken == null) throw new InvalidOperationException("Cannot get an Access token until you have the Request token."); var client = new RestClient(_apiBaseUrl) { Authenticator = OAuth1Authenticator.ForAccessToken(_consumerKey, _consumerSecret, requestToken.Value, requestToken.Secret) }; var request = new RestRequest(AccessTokenPath); var response = await client.ExecuteAsync(request); if (response.StatusCode == HttpStatusCode.OK) { var queryString = HttpUtility.ParseQueryString(response.Content); var accessToken = new AccessToken(queryString["oauth_token"], queryString["oauth_token_secret"]); return accessToken; } throw new Exception("An error occured: Status code: " + response.StatusCode, response.ErrorException); }