コード例 #1
0
        protected override void OnLoad(EventArgs e)
        {
            if (ConfigurationManager.AppSettings["XingConsumerKey"] == "xxx" || (ConfigurationManager.AppSettings["XingConsumerSecret"] == "xxx"))
            {
                liResult.Text = "Set XingConsumerKey and XingConsumerSecret in web.config";
            }
            else
            {
                this.Authorization = new WebOAuthAuthorization(this.TokenManager, this.AccessToken);

                if (!IsPostBack)
                {
                    string accessToken = this.Authorization.CompleteAuthorize();
                    if (accessToken != null)
                    {
                        this.AccessToken = accessToken;
                        Response.Redirect(Request.Path);
                    }

                    if (AccessToken == null)
                    {
                        this.Authorization.BeginAuthorize();
                    }
                    else
                    {
                        Test();
                    }
                }
            }

            base.OnLoad(e);
        }
コード例 #2
0
ファイル: LinkedInAuthorize.cs プロジェクト: Lietuva2/LT2
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            this.Session     = filterContext.HttpContext.Session;
            this.Application = filterContext.HttpContext.Application;



            this.Authorization = new WebOAuthAuthorization(this.TokenManager, this.AccessToken);
            string accessToken = this.Authorization.CompleteAuthorize();

            if (accessToken != null)
            {
                this.AccessToken = accessToken;
            }

            if (AccessToken == null)
            {
                this.Authorization.BeginAuthorize();
                filterContext.Result = new EmptyResult();
            }

            filterContext.Controller.ViewBag.LinkedInAuthorization = this.Authorization;

            base.OnActionExecuting(filterContext);
        }
コード例 #3
0
ファイル: ProvidersLocator.cs プロジェクト: DCT-UA/Monator
        private static BaseAuthenticationInfo LocateLinkedinResponse()
        {
            var    authorization = new WebOAuthAuthorization(LinkedinTokenManager, null);
            string accessToken;

            try
            {
                accessToken = authorization.CompleteAuthorize();
            }
            catch (Exception ex)
            {
                return(null);
            }
            if (accessToken != null)
            {
                authorization = new WebOAuthAuthorization(LinkedinTokenManager, accessToken);
                LinkedInService service = new LinkedInService(authorization);
                var             profile = service.GetCurrentUser(ProfileType.Public);
                var             info    = new LinkedinAuthenticationInfo();
                info.FirstName  = profile.FirstName;
                info.LastName   = profile.LastName;
                info.Identifier = profile.Id;
                info.UserName   = profile.Name;
                info.Provider   = providerModule.GetProvider("LinkedIn");
                return(info);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: DCT-UA/Monator
        public ActionResult LogOnUsingOpenId(string site)
        {
            var locatedUser = ProvidersLocator.LocateService();

            if (locatedUser != null)
            {
                var id = locatedUser.Identifier;
                if (!String.IsNullOrEmpty(id))
                {
                    Session.User = new User();
                    Session.User.ProviderUserId = id;
                    Session.User.ProviderId     = (int)locatedUser.Provider.Id;
                    var identifier = userModule.GetUserByProviderUserId(id);
                    if (identifier != null)
                    {
                        Session.User.Id = identifier.Id;
                        Session.User    = userModule.GetUser(identifier.UserName);

                        ViewData["UserName"] = Session.User.UserName;
                        FormsService.SignIn(identifier.UserName, false);
                        Session.SessionEndTime = DateTime.Now;
                        return(Redirect(Url.Home()));
                    }
                    else
                    {
                        ViewData["ProviderId"] = id;
                        return(Redirect(Url.Register(), true));
                    }
                }
            }

            switch (site)
            {
            case "twitter":
                var client = new TwitterClient(ProvidersLocator.TwitterTokenManager);
                client.StartAuthentication(Request.Url);
                break;

            case "google":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.Google.EndPoint);
                break;

            case "vkontakte":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.VKontakte.EndPoint);
                break;

            case "linkedin":
                var authorization = new WebOAuthAuthorization(ProvidersLocator.LinkedinTokenManager, null);
                var callback      = Request.Url;
                authorization.BeginAuthorize(callback);
                break;

            case "myspace":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.MySpace.EndPoint);
                break;
            }

            ViewData.Model = new AccountModel(new LogOnModel());
            return(View("LogOn"));
        }
コード例 #5
0
ファイル: Default.aspx.cs プロジェクト: omeryesil/awapicms
    protected void Page_Load(object sender, EventArgs e)
    {
        auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken);

        if (!Page.IsPostBack)
        {
            // try to complete a pending authorization in case there is one.
            string accessToken = auth.CompleteAuthorize();
            if (accessToken != null)
            {
                // Store the access token in session state so we can get at it across page refreshes.
                // In a real app, you'd want to associate this access token with the user that is
                // logged into your app at this point.
                InMemoryTokenManager.AccessToken = accessToken;

                // Clear away the OAuth message so that users can refresh the page without problems.
                Response.Redirect(Page.Request.Path);
            }
        }

        if (string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) || string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret))
        {
            // The user needs to set up the web.config file to include Twitter consumer key and secret.
            PrivateDataMultiView.SetActiveView(SetupTwitterConsumer);
        }
        else if (auth.CachedCredentialsAvailable)
        {
            auth.SignOn(); // acquire the screen name, and ensure the access token is still valid.
            screenNameLabel.Text = auth.ScreenName;
            PrivateDataMultiView.SetActiveView(ViewPrivateUpdates);
            updateBox.Focus();
        }
        else
        {
            PrivateDataMultiView.SetActiveView(AuthorizeTwitter);
        }

        twitterCtx = auth.CachedCredentialsAvailable ? new TwitterContext(auth) : new TwitterContext();

        var tweets =
            from tweet in twitterCtx.Status
            where tweet.Type == (auth.CachedCredentialsAvailable ? StatusType.Friends : StatusType.Public)
            select tweet;

        TwitterListView.DataSource = tweets;
        TwitterListView.DataBind();

        // demonstrate serialization

        var serializableUser =
            (from user in twitterCtx.User
             where user.Type == UserType.Show &&
             user.ScreenName == "JoeMayo"
             select user)
            .FirstOrDefault();

        // if you have ASP.NET state server turned on
        // this will still work because User is serializable
        Session["SerializableUser"] = serializableUser;
    }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: DCT-UA/Monator
        public ActionResult AccountBinding(BindingModel model, string site)
        {
            switch (site)
            {
            case "twitter":
                var client = new TwitterClient(ProvidersLocator.TwitterTokenManager);
                client.StartAuthentication(Request.Url);
                break;

            case "google":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.Google.EndPoint);
                break;

            case "vkontakte":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.VKontakte.EndPoint);
                break;

            case "linkedin":
                var authorization = new WebOAuthAuthorization(ProvidersLocator.LinkedinTokenManager, null);
                var callback      = Request.Url;
                authorization.BeginAuthorize(callback);
                break;

            case "myspace":
                TransferToOpenIdProvider(OpenIdProviderEndPoints.MySpace.EndPoint);
                break;

            default:
                int    curProviderId;
                string curProviderUserId;

                userBind = userModule.GetUserByProviderUserId(model.AccountBinding.ProviderUserId);
                if (userBind != null)
                {
                    userModule.CleanProvider(model.AccountBinding.ProviderUserId);
                }
                curProviderId     = model.AccountBinding.ProviderId;
                curProviderUserId = model.AccountBinding.ProviderUserId;

                if (userModule.AddProvider(curProviderId, curProviderUserId, Session.User.Id))
                {
                    HttpCookie providerCookie = new HttpCookie("SkynerCookie");

                    Session.User.ProviderId     = curProviderId;
                    Session.User.ProviderUserId = curProviderUserId;

                    providerCookie.Value = providerModule.GetProvider(Session.User.ProviderId).Name;
                    Response.Cookies.Add(providerCookie);

                    ViewData["UserName"] = Session.User.UserName;
                    ViewData.Model       = null;
                    return(RedirectToAction("AccountBindingSuccess", "Account"));
                }
                break;
            }
            model.Session = Session;
            return(View());
        }
コード例 #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken);

        if (string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) ||
            string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret) ||
            !auth.CachedCredentialsAvailable)
        {
            // Authorization occurs only on the home page.
            Response.Redirect("~/");
        }

        updateBox.Focus();
    }
コード例 #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        auth = new WebOAuthAuthorization(InMemoryTokenManager.Instance, InMemoryTokenManager.AccessToken);
        if (!string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerKey) &&
            !string.IsNullOrEmpty(InMemoryTokenManager.Instance.ConsumerSecret))
        {
            AuthMultiView.ActiveViewIndex = 1;

            if (!IsPostBack)
            {
                if (auth.CompleteAuthenticate())
                {
                    AuthMultiView.SetActiveView(SignedInView);
                    screenNameLabel.Text = auth.ScreenName;
                }
            }
        }
    }
コード例 #9
0
    protected override void OnLoad(EventArgs e)
    {
        this.Authorization = new WebOAuthAuthorization(this.TokenManager, this.AccessToken);

        if (!IsPostBack)
        {
            string accessToken = this.Authorization.CompleteAuthorize();
            if (accessToken != null)
            {
                this.AccessToken = accessToken;

                Response.Redirect(Request.Path);
            }

            if (AccessToken == null)
            {
                this.Authorization.BeginAuthorize();
            }
        }

        base.OnLoad(e);
    }
コード例 #10
0
    protected override void OnLoad(EventArgs e)
    {
        this.Authorization = new WebOAuthAuthorization(this.TokenManager, this.AccessToken);

        if (!IsPostBack)
        {
            string accessToken = this.Authorization.CompleteAuthorize();
            if (accessToken != null)
            {
                this.AccessToken = accessToken;

                Response.Redirect(Request.Path);
            }

            if (AccessToken == null)
            {
                Uri callback = new Uri(Page.ResolveUrl("http://localhost:1898/TestWeb/Default.aspx"));

                this.Authorization.BeginAuthorize(callback);
            }
        }

        base.OnLoad(e);
    }
コード例 #11
0
        private LinkedInService GetLinkedInService()
        {
            var authorization = new WebOAuthAuthorization(_tokenManager, _accessToken);

            return(new LinkedInService(authorization));
        }