Esempio n. 1
0
        internal LoginProfile ProfileFromOpenId(ClaimsResponse spprofile, FetchResponse fetchprofile, string claimedId, string realmUrlString)
        {
            var profile = new LoginProfile(Signature, InstanceCrypto)
            {
                Link     = claimedId,
                Id       = claimedId,
                Provider = ProviderConstants.OpenId,
            };

            if (spprofile != null)
            {
                //Fill
                profile.BirthDay    = spprofile.BirthDateRaw;
                profile.DisplayName = spprofile.FullName;
                profile.EMail       = spprofile.Email;
                profile.Name        = spprofile.Nickname;
                profile.Gender      = spprofile.Gender.HasValue ? spprofile.Gender.Value.ToString() : "";
                profile.TimeZone    = spprofile.TimeZone;
                profile.Locale      = spprofile.Language;
            }
            if (fetchprofile != null)
            {
                profile.Name        = fetchprofile.GetAttributeValue(WellKnownAttributes.Name.Alias);
                profile.LastName    = fetchprofile.GetAttributeValue(WellKnownAttributes.Name.Last);
                profile.FirstName   = fetchprofile.GetAttributeValue(WellKnownAttributes.Name.First);
                profile.DisplayName = fetchprofile.GetAttributeValue(WellKnownAttributes.Name.FullName);
                profile.MiddleName  = fetchprofile.GetAttributeValue(WellKnownAttributes.Name.Middle);
                profile.Salutation  = fetchprofile.GetAttributeValue(WellKnownAttributes.Name.Prefix);
                profile.Avatar      = fetchprofile.GetAttributeValue(WellKnownAttributes.Media.Images.Default);
                profile.EMail       = fetchprofile.GetAttributeValue(WellKnownAttributes.Contact.Email);
                profile.Gender      = fetchprofile.GetAttributeValue(WellKnownAttributes.Person.Gender);
                profile.BirthDay    = fetchprofile.GetAttributeValue(WellKnownAttributes.BirthDate.WholeBirthDate);
            }
            profile.RealmUrl = realmUrlString;
            return(profile);
        }
Esempio n. 2
0
 /// <summary>
 /// Gets the attribute value if available.
 /// </summary>
 /// <param name="fetchResponse">The AX fetch response extension to look for the attribute value.</param>
 /// <param name="typeUri">The type URI of the attribute, using the axschema.org format of <see cref="WellKnownAttributes"/>.</param>
 /// <param name="formats">The AX type URI formats to search.</param>
 /// <returns>
 /// The first value of the attribute, if available.
 /// </returns>
 internal static string GetAttributeValue(this FetchResponse fetchResponse, string typeUri, AXAttributeFormats formats)
 {
     return(ForEachFormat(formats).Select(format => fetchResponse.GetAttributeValue(TransformAXFormat(typeUri, format))).FirstOrDefault(s => s != null));
 }
Esempio n. 3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            SharedBasePage requestPage = Page as SharedBasePage;

            // only allow users to login using openid when we actually allow it
            if (requestPage.SiteConfig.AllowOpenIdComments == true)
            {
                OpenIdRelyingParty      openid   = new OpenIdRelyingParty();
                IAuthenticationResponse response = openid.GetResponse();
                if (response != null)
                {
                    // Stage 3: OpenID Provider sending assertion response
                    switch (response.Status)
                    {
                    case AuthenticationStatus.Authenticated:
                        ClaimsResponse sregResponse = response.GetExtension <ClaimsResponse>();
                        FetchResponse  axResponse   = response.GetExtension <FetchResponse>();
                        string         nick         = response.FriendlyIdentifierForDisplay;
                        string         homepage     = response.ClaimedIdentifier;
                        string         email        = "*****@*****.**";
                        if (sregResponse != null)
                        {
                            nick  = string.IsNullOrEmpty(sregResponse.Nickname) ? sregResponse.FullName : sregResponse.Nickname;
                            email = sregResponse.Email;
                        }

                        if (String.IsNullOrEmpty(nick) && axResponse != null && axResponse.Attributes.Contains(WellKnownAttributes.Name.First) && axResponse.Attributes.Contains(WellKnownAttributes.Name.Last))
                        {
                            nick = axResponse.GetAttributeValue(WellKnownAttributes.Name.First) + " " +
                                   axResponse.GetAttributeValue(WellKnownAttributes.Name.Last);
                        }

                        string comment = Session["pendingComment"] as string;
                        string entryId = Session["pendingEntryId"] as string;
                        if (String.IsNullOrEmpty(comment) == false && String.IsNullOrEmpty(entryId) == false)
                        {
                            AddNewComment(nick, email, homepage, comment, entryId, /* openid */ true);
                        }

                        break;
                    }
                }
            }

            // if you are commenting on your own blog, no need for Captha
            if (SiteSecurity.IsValidContributor())
            {
                CaptchaControl1.Enabled = CaptchaControl1.Visible = false;
            }
            else
            {
                CaptchaControl1.Enabled = CaptchaControl1.Visible = requestPage.SiteConfig.EnableCaptcha;
            }

            resmgr = ApplicationResourceTable.Get();

            if (!IsPostBack)
            {
                if (requestPage.WeblogEntryId.Length == 0)
                {
                    requestPage.Redirect(SiteUtilities.GetStartPageUrl(requestPage.SiteConfig));
                }
                ViewState["entryId"] = requestPage.WeblogEntryId;

                if (Request.Cookies["name"] != null)
                {
                    string nameStr = HttpUtility.UrlDecode(Request.Cookies["name"].Value, Encoding.UTF8);
                    //truncate at 32 chars to avoid abuse...
                    name.Text = nameStr.Substring(0, Math.Min(32, nameStr.Length));
                }

                if (Request.Cookies["email"] != null)
                {
                    email.Text = HttpUtility.UrlDecode(Request.Cookies["email"].Value, Encoding.UTF8);
                }

                if (Request.Cookies["homepage"] != null)
                {
                    homepage.Text = HttpUtility.UrlDecode(Request.Cookies["homepage"].Value, Encoding.UTF8);
                }

                if (Request.Cookies["openid"] != null)
                {
                    openid_identifier.Text = HttpUtility.UrlDecode(Request.Cookies["openid"].Value, Encoding.UTF8);
                }
            }

            DataBind();
        }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var openIdRelyingParty = new OpenIdRelyingParty();
            var openid_identifier  = ConfigurationManager.AppSettings["openid_identifier"];
            var returnUrl          = "~/OpenID/Connect.aspx";
            var response           = openIdRelyingParty.GetResponse();

            if (response == null)
            {
                // Stage 2: user submitting Identifier
                Identifier id;
                if (Identifier.TryParse(openid_identifier, out id))
                {
                    IAuthenticationRequest request = openIdRelyingParty.CreateRequest(openid_identifier);
                    FetchRequest           fetch   = new FetchRequest();
                    fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email));
                    fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.FullName));
                    fetch.Attributes.Add(new AttributeRequest("http://axschema.org/intuit/realmId"));
                    request.AddExtension(fetch);
                    request.RedirectToProvider();
                }
            }
            else
            {
                if (response.FriendlyIdentifierForDisplay == null)
                {
                    Response.Redirect("~/OpenID/Connect.aspx");
                }

                // Stage 3: OpenID Provider sending assertion response
                //Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
                FetchResponse fetch = response.GetExtension <FetchResponse>();
                if (fetch != null)
                {
                    var openIdEmail    = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
                    var openIdFullName = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName);
                    var openIdRealmId  = fetch.GetAttributeValue("http://axschema.org/intuit/realmId");

                    string userName = Membership.GetUserNameByEmail(openIdEmail);
                    if (userName == null)
                    {
                        Membership.CreateUser(openIdEmail, Guid.NewGuid().ToString(), openIdEmail);
                        FormsAuthentication.SetAuthCookie(openIdEmail, true);
                        if (Request.QueryString["Subscribe"] != null)
                        {
                            String csname           = "DirectConnectScript";
                            Type   cstype           = this.GetType();
                            ClientScriptManager csm = Page.ClientScript;

                            // Check to see if the startup script is already registered.
                            if (!csm.IsStartupScriptRegistered(cstype, csname))
                            {
                                StringBuilder cstext = new StringBuilder();
                                cstext.AppendLine("<script>");
                                cstext.AppendLine("$(document).ready(function () {");
                                cstext.AppendLine("intuit.ipp.anywhere.directConnectToIntuit();");
                                cstext.AppendLine("});");
                                cstext.AppendLine("</script>");
                                csm.RegisterStartupScript(cstype, csname, cstext.ToString());
                            }
                        }
                    }
                    else if (Request.QueryString["Disconnect"] != null)
                    {
                        RestHelper.clearProfile(RestProfile.GetRestProfile());
                        Response.Redirect("~/ManageConnection.aspx");
                    }
                    else if (userName != null)
                    {
                        FormsAuthentication.SetAuthCookie(userName, true);
                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            Response.Redirect("~/Default.aspx");
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Action Results for Index, uses DotNetOpenAuth for creating OpenId Request with Intuit
        /// and handling response recieved.
        /// </summary>
        /// <param name="sender">Sender of th event.</param>
        /// <param name="e">Event Args.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            var openid_identifier = ConfigurationManager.AppSettings["openid_identifier"];
            var returnUrl         = "OpenIdHandler.aspx";
            var response          = openid.GetResponse();

            if (response == null)
            {
                // Stage 2: user submitting Identifier
                Identifier id;
                if (Identifier.TryParse(openid_identifier, out id))
                {
                    try
                    {
                        IAuthenticationRequest request = openid.CreateRequest(openid_identifier);
                        FetchRequest           fetch   = new FetchRequest();
                        fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email));
                        fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.FullName));
                        request.AddExtension(fetch);
                        request.RedirectToProvider();
                    }
                    catch (ProtocolException ex)
                    {
                        throw ex;
                    }
                }
            }
            else
            {
                if (response.FriendlyIdentifierForDisplay == null)
                {
                    Response.Redirect("/OpenIdHandler.aspx");
                }

                // Stage 3: OpenID Provider sending assertion response
                Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
                FetchResponse fetch = response.GetExtension <FetchResponse>();
                if (fetch != null)
                {
                    Session["OpenIdResponse"] = "True";
                    Session["FriendlyEmail"]  = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); // emailAddresses.Count > 0 ? emailAddresses[0] : null;
                    Session["FriendlyName"]   = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName); //fullNames.Count > 0 ? fullNames[0] : null;

                    //get the Oauth Access token for the user from OauthAccessTokenStorage.xml
                    OauthAccessTokenStorageHelper.GetOauthAccessTokenForUser(Session["FriendlyEmail"].ToString(), Page);
                }

                string query = Request.Url.Query;
                if (!string.IsNullOrWhiteSpace(query) && query.ToLower().Contains("disconnect=true"))
                {
                    Session["accessToken"]       = "dummyAccessToken";
                    Session["accessTokenSecret"] = "dummyAccessTokenSecret";
                    Session["Flag"] = true;
                    Response.Redirect("CleanupOnDisconnect.aspx");
                }

                if (!string.IsNullOrEmpty(returnUrl))
                {
                    Response.Redirect("default.aspx");
                }
            }
        }