protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Аутентифицируемся при загрузке странички
                if (!IsPostBack)
                {
                    var yahoo = new WebConsumer(YahooConsumer.ServiceDescription, this.TokenManager);

                    // Is Google calling back with authorization?
                    var accessTokenResponse = yahoo.ProcessUserAuthorization();
                    if (accessTokenResponse != null)
                    {
                        AccessToken = accessTokenResponse.AccessToken;
                        YahooGuid = accessTokenResponse.ExtraData["xoauth_yahoo_guid"];
                        //Redirecting to result page
                        Response.Redirect("YahooAddressBook.aspx");
                    }
                    // If we don't yet have access, immediately request it.
                    YahooConsumer.RequestAuthorization(yahoo);
                }
            }
            catch (System.Threading.ThreadAbortException)
            {

            }
            catch (Exception ex)
            {
                SubmitError(ex.Message);
            }
        }
 public void RequestAuthorization()
 {
     _twitter = new WebConsumer(TwitterConsumer.ServiceDescription, TokenManager);
     var accessTokenResponse = _twitter.ProcessUserAuthorization();
     if (accessTokenResponse != null)
         AccessToken = accessTokenResponse.AccessToken;
     else
         _twitter.Channel.Send(_twitter.PrepareRequestUserAuthorization());
 }
Beispiel #3
0
        public ActionResult OAuthCallback()
        {
            var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, _consumerTokenManager);
            var accessTokenResponse = twitter.ProcessUserAuthorization();

            if (accessTokenResponse != null)
            {
                string userName = accessTokenResponse.ExtraData["screen_name"];
                return CreateUser(userName, null, null, null);
            }

            return RedirectToAction("LogOn");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.TokenManager != null)
            {
                this.MultiView1.ActiveViewIndex = 1;

                if (!IsPostBack)
                {
                    var xing = new WebConsumer(XingClient.ServiceDescription, this.TokenManager);

                    // Is Google calling back with authorization?
                    var accessTokenResponse = xing.ProcessUserAuthorization();
                    if (accessTokenResponse != null)
                    {
                        this.AccessToken = accessTokenResponse.AccessToken;
                        //Response.Redirect("/C1_netTestPage.aspx#/Home");
                        dynamic result = XingClient.GetMe(xing, this.AccessToken);
                        string display_name = result.display_name;
                        string id = result.id;
                        string first_name = result.first_name;
                        string last_name = result.last_name;
                        string picurl = result.photo_urls.maxi_thumb;
                        dynamic result2 = XingClient.GetMyContacts(xing, this.AccessToken, "display_name", 50, 0);
                        dynamic a = result2.contacts;
                        int b = a.total;
                        dynamic c = a.users;
                        int d = c.Count;

                        string display_name1 = c[0].display_name;
                        string id1 = c[0].id;

                        dynamic result3 = XingClient.GetUser(xing, this.AccessToken, id1, "photo_urls.medium_thumb");
                        string urli = result3.photo_urls.medium_thumb;
                        dynamic result4 = XingClient.GetUser(xing, this.AccessToken, id1, "active_email");
                        string mail = result3.active_email;
                        dynamic result5 = XingClient.GetUser(xing, this.AccessToken, c[12].id);
                        string url = XingClient.GetScopeUri(XingClient.Applications.me);
                        bool result6 = XingClient.PostStatus(xing, this.AccessToken, "Hura fertig!!! ", id);

                        //Response.Redirect("/#/Home");

                    }
                    else if (this.AccessToken == null)
                    {
                        // If we don't yet have access, immediately request it.
                        XingClient.RequestAuthorization(xing, XingClient.Applications.Contacts);
                    }
                }
            }
        }
Beispiel #5
0
        public ActionResult Login()
        {
            var oauthConsumer = new WebConsumer(Configuration.GetOauthConfiguration(), new JsonTokenManager(Request));
            var oauthResponse = oauthConsumer.ProcessUserAuthorization();

            if (oauthResponse != null)
            {
                FormsAuthentication.SetAuthCookie(oauthResponse.AccessToken, true);
                return RedirectToAction("Index");
            }

            var oauthRequest = oauthConsumer.PrepareRequestUserAuthorization(Request.Url, null, null);
            return oauthConsumer.Channel.PrepareResponse(oauthRequest).AsActionResult();
        }
        public bool FinishAuthentication()
        {
            using (var twitter = new WebConsumer(ServiceDescription, _tokenManager))
            {
                var accessTokenResponse = twitter.ProcessUserAuthorization();
                if (accessTokenResponse != null)
                {
                    AccessToken = accessTokenResponse.AccessToken;
                    SecretToken = _tokenManager.GetTokenSecret(AccessToken);
                    UserName = accessTokenResponse.ExtraData["screen_name"];
                    return true;
                }
            }

            return false;
        }
        public ActionResult About()
        {
            var twitter = new WebConsumer(TwitterConsumer.ServiceDescription,
                                            this.TokenManager);
            // Is Twitter calling back with authorization?
            var accessTokenResponse = twitter.ProcessUserAuthorization();
            if (accessTokenResponse != null)
            {
                this.AccessToken = accessTokenResponse.AccessToken;
            }
            else if (this.AccessToken == null)
            {
                // If we don't yet have access, immediately request it.
                twitter.Channel.Send(twitter.PrepareRequestUserAuthorization());
            }

            return View();
        }
Beispiel #8
0
		protected void Page_Load(object sender, EventArgs e) {
			if (this.TokenManager != null) {
				this.MultiView1.ActiveViewIndex = 1;

				if (!IsPostBack) {
					var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager);

					// Is Twitter calling back with authorization?
					var accessTokenResponse = twitter.ProcessUserAuthorization();
					if (accessTokenResponse != null) {
						this.AccessToken = accessTokenResponse.AccessToken;
					} else if (this.AccessToken == null) {
						// If we don't yet have access, immediately request it.
						twitter.Channel.Respond(twitter.PrepareRequestUserAuthorization());
					}
				}
			}
		}
        public void ProcessAuthRequest(IConsumerTokenManager tokenManager)
        {
            _webConsumer = new WebConsumer(TwitterConsumer.SignInWithTwitterServiceDescription, tokenManager);

            var response = _webConsumer.ProcessUserAuthorization();

            if (response == null)
            {
                return;
            }

            var screenName = response.ExtraData["screen_name"];
            var userId = int.Parse(response.ExtraData["user_id"]);

            UserId = userId.ToString(CultureInfo.CurrentCulture);
            UserName = screenName;
            PictureUrl = string.Format("http://api.twitter.com/1/users/profile_image/{0}.png", screenName);
        }
		protected void Page_Load(object sender, EventArgs e) {
			if (this.TokenManager != null) {
				this.MultiView1.ActiveViewIndex = 1;

				if (!IsPostBack) {
					var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager);

					// Is Google calling back with authorization?
					var accessTokenResponse = google.ProcessUserAuthorization();
					if (accessTokenResponse != null) {
						this.AccessToken = accessTokenResponse.AccessToken;
					} else if (this.AccessToken == null) {
						// If we don't yet have access, immediately request it.
						GoogleConsumer.RequestAuthorization(google, GoogleConsumer.Applications.Contacts);
					}
				}
			}
		}
        public ActionResult OAuthCallback()
        {
            smugmug myMug = new smugmug();
            // Process result from the service provider
            var serviceProvider = myMug.GetServiceDescription();
            var consumer = new WebConsumer(serviceProvider, myMug.InMemoryTokenManager);
            var accessTokenResponse = consumer.ProcessUserAuthorization(this.HttpContext.Request);
            var test = this.HttpContext.Request;
            // If we didn't have an access token response, this wasn't called by the service provider
            if (accessTokenResponse == null)
                return RedirectToAction("Index");

            // Extract the access token
            string accessToken = accessTokenResponse.AccessToken;

            ViewBag.Token = accessToken;
            ViewBag.Secret = myMug.InMemoryTokenManager.GetTokenSecret(accessToken);
            return View();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //NOTE: removed. so every page will provide google auth dialog
                if (AccessToken != null)
                {
                    //Previously stored token. clean it
                    ImportConfiguration.GoogleTokenManager.ExpireToken(AccessToken);
                }

                //Authenticating when loading pages
                if (!IsPostBack)
                {
                    using (
                        var google = new WebConsumer(GoogleConsumer.ServiceDescription,
                                                     ImportConfiguration.GoogleTokenManager))
                    {
                        // Is Google calling back with authorization?
                        var accessTokenResponse = google.ProcessUserAuthorization();
                        if (accessTokenResponse != null)
                        {
                            AccessToken = accessTokenResponse.AccessToken;
                            //Redirecting to result page
                            SubmitToken(AccessToken, Source);
                        }
                        else
                        {
                           GoogleConsumer.RequestAuthorization(google, "https://docs.google.com/feeds/ https://spreadsheets.google.com/feeds/ https://docs.googleusercontent.com/");

                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                SubmitError(ex.Message, Source);
            }
        }
        protected void identifierBox_LoggedIn(object sender, OpenIdEventArgs e)
        {
            State.FetchResponse = e.Response.GetExtension<FetchResponse>();

            ServiceProviderDescription serviceDescription = new ServiceProviderDescription {
                AccessTokenEndpoint = new MessageReceivingEndpoint(new Uri(e.Response.Provider.Uri, "/access_token.ashx"), HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest),
                TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
            };
            WebConsumer consumer = new WebConsumer(serviceDescription, Global.OwnSampleOPHybridTokenManager);

            AuthorizedTokenResponse accessToken = consumer.ProcessUserAuthorization(e.Response);
            if (accessToken != null) {
                this.MultiView1.SetActiveView(this.AuthorizationGiven);

                // At this point, the access token would be somehow associated with the user
                // account at the RP.
                ////Database.Associate(e.Response.ClaimedIdentifier, accessToken.AccessToken);
            } else {
                this.MultiView1.SetActiveView(this.AuthorizationDenied);
            }

            // Avoid the redirect
            e.Cancel = true;
        }
 /// <summary>
 /// Tries to get information the service provider and revalidates it.
 /// </summary>
 /// <param name="tokenManager"></param>
 /// <param name="reissueCallback">If not null, the flow will be restarted/reissued when the parameters are incorrect (due to token invalid or expired).</param>
 /// <param name="userId"></param>
 /// <param name="accessToken"></param>
 /// <returns>true if success, false if fail</returns>
 public static bool TryFinishOAuthFlow(IConsumerTokenManager tokenManager, ILoggerService logger, out long userId, out string accessToken)
 {
     bool success = false;
     var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, tokenManager);
     userId = 0;
     accessToken = null;
     // Is Twitter calling back with authorization?
     try
     {
         var accessTokenResponse = twitter.ProcessUserAuthorization();
         if (accessTokenResponse != null)
         {
             accessToken = accessTokenResponse.AccessToken;
             userId = Convert.ToInt64(accessTokenResponse.ExtraData["user_id"]);
             success = true;
         }
     }
     catch (DotNetOpenAuth.Messaging.ProtocolException ex)
     {
         //Can failed because the token manager didn't find the key or the service is not available.
         logger.LogError(ex);
     }
     return success;
 }
 public ActionResult TwitterOAuthCallback()
 {
     var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, _consumerTokenManager);
     AuthorizedTokenResponse accessTokenResponse = twitter.ProcessUserAuthorization();
     if (accessTokenResponse != null)
     {
         string userName = accessTokenResponse.ExtraData["screen_name"];
         //return CreateUser(userName, null, null, null);
     }
     //_logger.Error("OAuth: No access token response!");
     return RedirectToAction("Authenticate");
 }
        /// <summary>
        /// Checks the incoming web request to see if it carries a Twitter authentication response,
        /// and provides the user's Twitter screen name and unique id if available.
        /// </summary>
        /// <param name="screenName">The user's Twitter screen name.</param>
        /// <param name="userId">The user's Twitter unique user ID.</param>
        /// <returns>
        /// A value indicating whether Twitter authentication was successful;
        /// otherwise <c>false</c> to indicate that no Twitter response was present.
        /// </returns>
        public bool CompleteAuthenticate()
        {
            using (WebConsumer consumer = new WebConsumer(SignInWithTwitterServiceDescription, this.Consumer.TokenManager))
            {
                var response = consumer.ProcessUserAuthorization();
                if (response == null)
                {
                    return false;
                }

                this.ParseUserInfoFromAuthorizationResult(response.ExtraData);
                return true;
            }
        }