예제 #1
0
		protected string SignedPost (string url, IDictionary<string,string> parameters, OAuth.Token token) {			
			HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
			request.Method = "POST";
			request.ContentType = "application/x-www-form-urlencoded";
			request.Headers.Add ("Authorization", OAuth.Sign (Consumer, url, parameters, token, "POST", null));
			StreamWriter streamWriter = new StreamWriter (request.GetRequestStream ());
			streamWriter.Write (OAuth.PercentEscape (parameters));
			streamWriter.Close ();
			
			HttpWebResponse response;
			try {
				response = (HttpWebResponse)request.GetResponse ();
			} catch(WebException e) {
				RdioException re;
				response = (HttpWebResponse)e.Response;
				if (response.StatusCode == HttpStatusCode.Forbidden ||
				    response.StatusCode == HttpStatusCode.Unauthorized) {
					re = new AuthorizationException();
				} else {
					re = new RdioException();
				}
				re.Request = request;
				re.Response = response;
				re.Exception = e;
				throw re;
			}
			StreamReader streamReader = new StreamReader (response.GetResponseStream ());
			return streamReader.ReadToEnd ();
		}
예제 #2
0
		public RdioClient (OAuth.Consumer consumer, OAuth.Token accessToken)
		{
			Consumer = consumer;
			AccessToken = accessToken;
		}
예제 #3
0
			public AuthState(OAuth.Token requestToken, string url) {
				RequestToken = requestToken;
				Url = url;
			}
예제 #4
0
		public RdioClient (OAuth.Consumer consumer)
		{
			Consumer = consumer;
		}
예제 #5
0
		public OAuth.Token CompleteAuthentication(string verifier, OAuth.Token requestToken) {
			string response = SignedPost ("http://api.rdio.com/oauth/access_token",
			                              new Dictionary<string,string> { { "oauth_verifier", verifier } }, 
										  requestToken);
			NameValueCollection parsed = HttpUtility.ParseQueryString(response);
			return new OAuth.Token(parsed["oauth_token"], parsed["oauth_token_secret"]);
		}