Ejemplo n.º 1
0
		/// <summary>
		/// Completes the OAuth authorization request using the verifier supplied by the user.
		/// </summary>
		/// <param name="state">The original <seealso cref="OAuthRequestState"/> object containing the request token.</param>
		/// <param name="verifier">The verification code informed by the user.</param>
		/// <returns>The <seealso cref="OAuthToken"/> containing the Access Token.</returns>
		public async Task<OAuthToken> CompleteUserAuthorizationAsync(OAuthRequestState state, string verifier)
		{
			if (string.IsNullOrEmpty(verifier))
				throw new ArgumentNullException("verifier");

			if (state == null)
				throw new ArgumentNullException("state");

			var request = OAuthRequest.ForAccessToken(Credentials.ConsumerKey, Credentials.ConsumerSecret, state.RequestToken.Token, state.RequestToken.Secret, verifier);

			var httpRequest = request.CreateRequestWithAuthorizationHeader(_serviceDescription.AccessTokenEndpoint);

			using (var httpResponse = await httpRequest.GetHttpWebResponseAsync())
			{
				httpResponse.EnsureSuccessStatusCode();

				var accessToken = httpResponse.GetToken();

				Credentials.Token = accessToken.Copy();

				return accessToken;
			}
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Completes the OAuth authorization request using HttpContext.Current.
		/// </summary>
		/// <param name="state">The original <seealso cref="OAuthRequestState"/> object containing the request token.</param> 
		/// <returns>The <seealso cref="OAuthToken"/> containing the Access Token.</returns>
		public Task<OAuthToken> CompleteUserAuthorizationAsync(OAuthRequestState state)
		{
			if (HttpContext.Current == null)
				throw new RdioException("HttpContext.Current must not be null.");

			var verifier = HttpContext.Current.Request.Params["oauth_verifier"];

			return CompleteUserAuthorizationAsync(verifier);
		}