public async override Task<ActionResult> IndexAsync(AuthorizationCodeResponseUrl authorizationCode,
            CancellationToken taskCancellationToken)
        {
            if (string.IsNullOrEmpty(authorizationCode.Code))
            {
                var errorResponse = new TokenErrorResponse(authorizationCode);
                Logger.Info("Received an error. The response is: {0}", errorResponse);

                return OnTokenError(errorResponse);
            }

            Logger.Debug("Received \"{0}\" code", authorizationCode.Code);

            var returnUrl = Request.Url.ToString();
            returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?"));

            var token = await Flow.ExchangeCodeForTokenAsync(UserId, authorizationCode.Code, returnUrl,
                taskCancellationToken).ConfigureAwait(false);

            // Extract the right state.
            var oauthState = await AuthWebUtility.ExtracRedirectFromState(Flow.DataStore, UserId, authorizationCode.State).ConfigureAwait(false);

            string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(token);
            System.IO.File.WriteAllText("D://json.txt", json);

            return RedirectToAction("Index", "Home");
            //TODO: Move to Home/Connect
            //ToDO: move to Home/Upload
            //TODO: Load from Disk
        }
        public void TestConstructor_Query()
        {
            string query    = "code=123&error=ERR&error_uri=URI&error_description=DESC&state=STATE&other_ine=2222222222";
            var    response = new AuthorizationCodeResponseUrl(query);

            SubtestConstructor(response);
        }
        public async virtual Task<ActionResult> IndexAsync(AuthorizationCodeResponseUrl authorizationCode,
            CancellationToken taskCancellationToken)
        {
            if (string.IsNullOrEmpty(authorizationCode.Code))
            {
                var errorResponse = new TokenErrorResponse(authorizationCode);
                Logger.Info("Received an error. The response is: {0}", errorResponse);

                return OnTokenError(errorResponse);
            }

            Logger.Debug("Received \"{0}\" code", authorizationCode.Code);

            var returnUrl = Request.Url.ToString();
            returnUrl = returnUrl.Substring(0, returnUrl.IndexOf("?"));

            var token = await Flow.ExchangeCodeForTokenAsync(UserId, authorizationCode.Code, returnUrl,
                taskCancellationToken).ConfigureAwait(false);

            // Extract the right state.
            var oauthState = await AuthWebUtility.ExtracRedirectFromState(Flow.DataStore, UserId,
                authorizationCode.State).ConfigureAwait(false);

            return new RedirectResult(oauthState);
        }
 private void SubtestConstructor(AuthorizationCodeResponseUrl response)
 {
     Assert.That(response.Code, Is.EqualTo("123"));
     Assert.That(response.Error, Is.EqualTo("ERR"));
     Assert.That(response.ErrorUri, Is.EqualTo("URI"));
     Assert.That(response.ErrorDescription, Is.EqualTo("DESC"));
     Assert.That(response.State, Is.EqualTo("STATE"));
 }
 private void SubtestConstructor(AuthorizationCodeResponseUrl response)
 {
     Assert.That(response.Code, Is.EqualTo("123"));
     Assert.That(response.Error, Is.EqualTo("ERR"));
     Assert.That(response.ErrorUri, Is.EqualTo("URI"));
     Assert.That(response.ErrorDescription, Is.EqualTo("DESC"));
     Assert.That(response.State, Is.EqualTo("STATE"));
 }
 public void TestConstructor_Default()
 {
     var response = new AuthorizationCodeResponseUrl();
     Assert.Null(response.Code);
     Assert.Null(response.Error);
     Assert.Null(response.ErrorUri);
     Assert.Null(response.ErrorDescription);
     Assert.Null(response.State);
 }
        public void TestConstructor_Default()
        {
            var response = new AuthorizationCodeResponseUrl();

            Assert.Null(response.Code);
            Assert.Null(response.Error);
            Assert.Null(response.ErrorUri);
            Assert.Null(response.ErrorDescription);
            Assert.Null(response.State);
        }
        public void TestConstructor_Dictionary()
        {
            var dic = new Dictionary<string, string>();
            dic["code"] = "123";
            dic["error"] = "ERR";
            dic["error_uri"] = "URI";
            dic["error_description"] = "DESC";
            dic["state"] = "STATE";

            // Some other parameter, which is not part of the response.
            dic["another_one"] = "BLAH BLAH BLAH";

            var response = new AuthorizationCodeResponseUrl(dic);
            SubtestConstructor(response);
        }
        public void TestConstructor_Dictionary()
        {
            var dic = new Dictionary <string, string>();

            dic["code"]              = "123";
            dic["error"]             = "ERR";
            dic["error_uri"]         = "URI";
            dic["error_description"] = "DESC";
            dic["state"]             = "STATE";

            // Some other parameter, which is not part of the response.
            dic["another_one"] = "BLAH BLAH BLAH";

            var response = new AuthorizationCodeResponseUrl(dic);

            SubtestConstructor(response);
        }
 public void TestConstructor_Query()
 {
     string query = "code=123&error=ERR&error_uri=URI&error_description=DESC&state=STATE&other_ine=2222222222";
     var response = new AuthorizationCodeResponseUrl(query);
     SubtestConstructor(response);
 }
		/// <summary>
		/// Setups the listener.
		/// </summary>
		private async void SetupListener()
		{
			mlistener = new HttpListener();
			mlistener.Prefixes.Add(mRedirectUrl);
			mlistener.Start();

			var context = await mlistener.GetContextAsync().ConfigureAwait(false);
			NameValueCollection coll = context.Request.QueryString;

			// Write a "close" response.
			using (var writer = new StreamWriter(context.Response.OutputStream))
			{
				writer.WriteLine(ClosePageResponse);
				writer.Flush();
			}

			context.Response.OutputStream.Close();

			mItem = new AuthorizationCodeResponseUrl(coll.AllKeys.ToDictionary(k => k, k => coll[k]));
		}
Example #12
0
 /// <summary>Constructs a new token error response from the given authorization code response.</summary>
 public TokenErrorResponse(AuthorizationCodeResponseUrl authorizationCode)
 {
     Error            = authorizationCode.Error;
     ErrorDescription = authorizationCode.ErrorDescription;
     ErrorUri         = authorizationCode.ErrorUri;
 }