Beispiel #1
0
        protected void yesButton_Click(object sender, EventArgs e)
        {
            this.outerMultiView.SetActiveView(this.authorizationGrantedView);

            var consumer       = OAuthServiceProvider.PendingAuthorizationConsumer;
            var tokenManager   = OAuthServiceProvider.ServiceProvider.TokenManager;
            var pendingRequest = OAuthServiceProvider.PendingAuthorizationRequest;
            ITokenContainingMessage requestTokenMessage = pendingRequest;
            var requestToken = tokenManager.GetRequestToken(requestTokenMessage.Token);

            OAuthServiceProvider.AuthorizePendingRequestToken();

            // The rest of this method only executes if we couldn't automatically
            // redirect to the consumer.
            if (pendingRequest.IsUnsafeRequest)
            {
                this.verifierMultiView.SetActiveView(this.noCallbackView);
            }
            else
            {
                this.verifierMultiView.SetActiveView(this.verificationCodeView);
                string verifier = ServiceProvider.CreateVerificationCode(consumer.VerificationCodeFormat, consumer.VerificationCodeLength);
                this.verificationCodeLabel.Text = HttpUtility.HtmlEncode(verifier);
                requestToken.VerificationCode   = verifier;
                tokenManager.UpdateToken(requestToken);
            }
        }
Beispiel #2
0
        private void TestCode(VerificationCodeFormat format, int length, string allowableCharacters)
        {
            string code = ServiceProvider.CreateVerificationCode(format, length);

            TestUtilities.TestLogger.InfoFormat("{0} of length {2}: {1}", format, code, length);
            Assert.AreEqual(length, code.Length);
            foreach (char ch in code)
            {
                Assert.IsTrue(allowableCharacters.Contains(ch));
            }
        }
Beispiel #3
0
        protected void allowAccessButton_Click(object sender, EventArgs e)
        {
            this.RegisterAsyncTask(
                new PageAsyncTask(
                    async ct => {
                if (this.AuthorizationSecret != this.OAuthAuthorizationSecToken.Value)
                {
                    throw new ArgumentException();                               // probably someone trying to hack in.
                }
                this.AuthorizationSecret = null;                                 // clear one time use secret
                var pending = Global.PendingOAuthAuthorization;
                Global.AuthorizePendingRequestToken();
                this.multiView.ActiveViewIndex = 1;

                ServiceProvider sp = new ServiceProvider(Constants.SelfDescription, Global.TokenManager);
                var response       = sp.PrepareAuthorizationResponse(pending);
                if (response != null)
                {
                    var responseMessage = await sp.Channel.PrepareResponseAsync(response, Response.ClientDisconnectedToken);
                    await responseMessage.SendAsync();
                    this.Context.Response.End();
                }
                else
                {
                    if (pending.IsUnsafeRequest)
                    {
                        this.verifierMultiView.ActiveViewIndex = 1;
                    }
                    else
                    {
                        string verifier = ServiceProvider.CreateVerificationCode(VerificationCodeFormat.AlphaNumericNoLookAlikes, 10);
                        this.verificationCodeLabel.Text             = verifier;
                        ITokenContainingMessage requestTokenMessage = pending;
                        var requestToken = Global.TokenManager.GetRequestToken(requestTokenMessage.Token);
                        requestToken.VerificationCode = verifier;
                        Global.TokenManager.UpdateToken(requestToken);
                    }
                }
            }));
        }
        /// <summary> </summary>
        protected void Authtorize_Click(object sender, EventArgs e)
        {
            if (this.AuthorizationSecret != this.OAuthAuthorizationSecToken.Value)
            {
                throw new ArgumentException(); // probably someone trying to hack in.
            }
            this.AuthorizationSecret = null;   // clear one time use secret
            var pending = GlobalApplication.PendingOAuthAuthorization;

            GlobalApplication.AuthorizePendingRequestToken();
            this.multiView.ActiveViewIndex = 1;

            ServiceProvider sp       = new ServiceProvider(Constants.SelfDescription, GlobalApplication.TokenManager);
            var             response = sp.PrepareAuthorizationResponse(pending);

            if (response != null)
            {
                sp.Channel.Send(response);
            }
            else
            {
                if (pending.IsUnsafeRequest)
                {
                    this.verifierMultiView.ActiveViewIndex = 1;
                }
                else
                {
                    string verifier = ServiceProvider.CreateVerificationCode(VerificationCodeFormat.AlphaNumericNoLookAlikes, 10);
                    this.verificationCodeLabel.Text = verifier;
                    ITokenContainingMessage requestTokenMessage = pending;
                    var requestToken = GlobalApplication.TokenManager.GetRequestToken(requestTokenMessage.Token);
                    requestToken.VerificationCode = verifier;
                    GlobalApplication.TokenManager.UpdateToken(requestToken);
                }
            }
        }
Beispiel #5
0
        public ActionResult Authorize(bool isApproved)
        {
            if (isApproved)
            {
                var consumer       = OAuthServiceProvider.PendingAuthorizationConsumer;
                var tokenManager   = OAuthServiceProvider.ServiceProvider.TokenManager;
                var pendingRequest = OAuthServiceProvider.PendingAuthorizationRequest;
                ITokenContainingMessage requestTokenMessage = pendingRequest;
                var requestToken = tokenManager.GetRequestToken(requestTokenMessage.Token);

                var response = OAuthServiceProvider.AuthorizePendingRequestTokenAsWebResponse();
                if (response != null)
                {
                    // The consumer provided a callback URL that can take care of everything else.
                    return(response.AsActionResult());
                }

                var model = new AccountAuthorizeModel {
                    ConsumerApp = consumer.Name,
                };

                if (!pendingRequest.IsUnsafeRequest)
                {
                    model.VerificationCode        = ServiceProvider.CreateVerificationCode(consumer.VerificationCodeFormat, consumer.VerificationCodeLength);
                    requestToken.VerificationCode = model.VerificationCode;
                    tokenManager.UpdateToken(requestToken);
                }

                return(View("AuthorizeApproved", model));
            }
            else
            {
                OAuthServiceProvider.PendingAuthorizationRequest = null;
                return(View("AuthorizeDenied"));
            }
        }