コード例 #1
0
		/// <summary>
		/// Requests authorization from Google to access data from a set of Google applications.
		/// </summary>
		/// <param name="consumer">The Google consumer previously constructed using <see cref="CreateWebConsumer"/> or <see cref="CreateDesktopConsumer"/>.</param>
		/// <param name="requestedAccessScope">The requested access scope.</param>
		public static void RequestAuthorization(WebConsumer consumer) {
			if (consumer == null) {
				throw new ArgumentNullException("consumer");
			}

			Uri callback = Util.GetCallbackUrlFromContext();
			var request = consumer.PrepareRequestUserAuthorization(callback, null, null);
			consumer.Channel.Send(request);
		}
コード例 #2
0
        public ActionResult OAuth(string returnUrl)
        {
            var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, _consumerTokenManager);
            var url = Request.Url.ToString().Replace("OAuth", "OAuthCallback");
            var callbackUri = new Uri(url);
            twitter.Channel.Send(twitter.PrepareRequestUserAuthorization(callbackUri, null, null));

            return RedirectToAction("LogOn");
        }
コード例 #3
0
 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());
 }
コード例 #4
0
 //http://api.linkedin.com/v1/people/~
 public static void RequestAuthorization(WebConsumer consumer)
 {
     if (consumer == null)
     {
         throw new ArgumentNullException("consumer");
     }
     Uri callback = HttpRequestExtensions.GetUrlRewriter(HttpContext.Current.Request.Headers, Util.GetCallbackUrlFromContext().StripQueryArgumentsWithPrefix("oauth_"));
     var request = consumer.PrepareRequestUserAuthorization(callback, null, null);
     consumer.Channel.Send(request);
 }
コード例 #5
0
 public void StartAuthentication()
 {
     var request = HttpContext.Current.Request;
     using (var twitter = new WebConsumer(ServiceDescription, _tokenManager))
     {
         var callBackUrl = new Uri(request.Url.Scheme + "://" + request.Url.Authority + CallBackUrl);
         twitter.Channel.Send(
             twitter.PrepareRequestUserAuthorization(callBackUrl, null, null)
         );
     }
 }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: nordineb/EverMark
        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();
        }
コード例 #7
0
        public ActionResult StartOAuth()
        {
            smugmug myMug = new smugmug();

            var serviceProvider = myMug.GetServiceDescription();
            var consumer = new WebConsumer(serviceProvider, myMug.InMemoryTokenManager);

            // Url to redirect to
            var authUrl = new Uri(Request.Url.Scheme + "://" + Request.Url.Authority + "/OAuth/OAuthCallBack/");

            // request access

            consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null));

            // This will not get hit!
            return null;
        }
コード例 #8
0
        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();
        }
コード例 #9
0
ファイル: Twitter.aspx.cs プロジェクト: enslam/dotnetopenid
		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());
					}
				}
			}
		}
コード例 #10
0
        public ActionResult PrepareAuthRequest(Uri callback, IConsumerTokenManager tokenManager)
        {
            _webConsumer = new WebConsumer(GoogleConsumer.ServiceDescription, tokenManager);

            var accessToken = GetAccessToken();

            if (string.IsNullOrEmpty(accessToken))
            {
                var extraParameters = new Dictionary<string, string>();

                extraParameters.Add("scope", "https://www.googleapis.com/auth/userinfo.profile");
                var request = _webConsumer.PrepareRequestUserAuthorization(callback, extraParameters, null);

                return _webConsumer.Channel.PrepareResponse(request).AsActionResult();
            }

            return null;
        }
コード例 #11
0
        public ActionResult PrepareAuthRequest(Uri callback, IConsumerTokenManager tokenManager)
        {
            _webConsumer = new WebConsumer(TwitterConsumer.SignInWithTwitterServiceDescription, tokenManager);

            var token = GetAccessToken();

            if (string.IsNullOrEmpty(token))
            {
                var redirectParameters = new Dictionary<string, string>();

                redirectParameters["force_login"] = "******";

                var request = _webConsumer.PrepareRequestUserAuthorization(callback, null, redirectParameters);

                return _webConsumer.Channel.PrepareResponse(request).AsActionResult();
            }

            return null;
        }
コード例 #12
0
        /// <summary>
        /// Requests authorization from Google to access data from a set of Google applications.
        /// </summary>
        /// <param name="consumer">The Google consumer previously constructed using <see cref="CreateWebConsumer"/> or <see cref="CreateDesktopConsumer"/>.</param>
        /// <param name="requestedAccessScope">The requested access scope.</param>
        public static void RequestAuthorization(WebConsumer consumer, Applications requestedAccessScope)
        {
            if (consumer == null) {
                throw new ArgumentNullException("consumer");
            }

            var extraParameters = new Dictionary<string, string> {
                { "scope", GetScopeUri(requestedAccessScope) },
            };
            Uri callback = Util.GetCallbackUrlFromContext();
            var request = consumer.PrepareRequestUserAuthorization(callback, extraParameters, null);
            consumer.Channel.Send(request);
        }
コード例 #13
0
 /// <summary>
 /// Requests authorization from ODesk to access API data
 /// </summary>
 public static void RequestAuthorization(WebConsumer consumer)
 {
     if (consumer == null)
     {
         throw new ArgumentNullException("consumer");
     }
     var callback = Utility.GetCallbackUrlFromContext();
     consumer.Channel.Send(consumer.PrepareRequestUserAuthorization());
 }
コード例 #14
0
 /// <summary>
 /// Starts OAuth by getting a request Token and redirecting the user to the provider.
 /// </summary>
 /// <param name="tokenManager"></param>
 public static void StartOAuthFlow(IConsumerTokenManager tokenManager, Uri callback=null)
 {
     var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, tokenManager);
     UserAuthorizationRequest usr = twitter.PrepareRequestUserAuthorization(callback, null, null);
     twitter.Channel.Send(usr);
 }
コード例 #15
0
        //[HttpPost]
        public ActionResult AuthenticateWithTwitter()
        {
            if (Request.Url == null)
            {
                return View("AuthenticateIndex");
            }

            var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, _consumerTokenManager);
            var callBackUrl = CreateUri(Request.Url, "Account/TwitterOAuthCallback");
            twitter.Channel.Send(twitter.PrepareRequestUserAuthorization(callBackUrl, null, null));

            return RedirectToAction("Authenticate");
        }
コード例 #16
0
 /// <summary>
 /// Prepares a redirect that will send the user to Twitter to sign in.
 /// </summary>
 /// <param name="forceNewLogin">if set to <c>true</c> the user will be required to re-enter their Twitter credentials even if already logged in to Twitter.</param>
 public void BeginAuthenticate(bool forceNewLogin)
 {
     using (WebConsumer consumer = new WebConsumer(SignInWithTwitterServiceDescription, this.Consumer.TokenManager))
     {
         var redirectParameters = new Dictionary<string, string>();
         if (forceNewLogin)
         {
             redirectParameters["force_login"] = "******";
         }
         Uri callback = MessagingUtilities.GetRequestUrlFromContext().StripQueryArgumentsWithPrefix("oauth_");
         var request = consumer.PrepareRequestUserAuthorization(callback, null, redirectParameters);
         consumer.Channel.Send(request);
     }
 }