Esempio n. 1
0
    /// <summary>
    /// Authenticates the request from the OpenID provider.
    /// </summary>
    public static OpenIdData Authenticate()
    {
        OpenIdData data = (OpenIdData)HttpContext.Current.Session["openid"];

        // Make sure the client has been through the Login method
        if (data == null)
        {
            return(new OpenIdData(string.Empty));
        }

        NameValueCollection query = HttpContext.Current.Request.QueryString;

        // Make sure the incoming request's identity matches the one stored in session
        //if (query["openid.claimed_id"] != data.Identity)
        //  return data;

        data = new OpenIdData(string.Empty, query["openid.mode"] == "id_res");
        NameValueCollection nameValueColl = new NameValueCollection();

        foreach (string name in query.Keys)
        {
            nameValueColl.Add(name.Replace("openid.sreg.", string.Empty), query[name]);
        }

        data = new OpenIdData(string.Empty, query["openid.mode"] == "id_res", nameValueColl);
        HttpContext.Current.Session.Remove("openid");
        return(data);
    }
    /// <summary>
    /// Authenticates the request from the OpenID provider.
    /// </summary>
    public static OpenIdData Authenticate()
    {
        OpenIdData data = (OpenIdData)HttpContext.Current.Session["openid"];

        // Make sure the client has been through the Login method
        if (data == null)
            return new OpenIdData(string.Empty);

        NameValueCollection query = HttpContext.Current.Request.QueryString;

        // Make sure the incoming request's identity matches the one stored in session
        //if (query["openid.claimed_id"] != data.Identity)
        //  return data;

        data = new OpenIdData(string.Empty, query["openid.mode"] == "id_res");
        NameValueCollection nameValueColl = new NameValueCollection();
        foreach (string name in query.Keys)
        {
            nameValueColl.Add(name.Replace("openid.sreg.", string.Empty), query[name]);
        }

        data = new OpenIdData(string.Empty, query["openid.mode"] == "id_res", nameValueColl);
        HttpContext.Current.Session.Remove("openid");
        return data;
    }
Esempio n. 3
0
    /// <summary>
    /// Redirects user to login page if he is not already authenticated
    /// </summary>
    /// <param name="opendIdProviderUrl">OpenId Provider Url.</param>
    /// <param name="identity">Identity value.</param>
    /// <param name="claimedId">Claim identifier.</param>
    /// <param name="requiredParameters">Required Parameters.</param>
    /// <param name="optionalParameters">Optional Parameters.</param>
    /// <returns>True if login was successful.</returns>
    public static bool Login(string opendIdProviderUrl, string identity, string claimedId, string requiredParameters, string optionalParameters)
    {
        try
        {
            if (!string.IsNullOrEmpty(opendIdProviderUrl))
            {
                string     redirectUrl = CreateRedirectUrl(requiredParameters, optionalParameters, claimedId, identity);
                OpenIdData data        = new OpenIdData(identity);
                HttpContext.Current.Session["openid"] = data;
                HttpContext.Current.Response.Redirect(opendIdProviderUrl + redirectUrl, true);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return(false);
    }
    /// <summary>
    /// Redirects user to login page if he is not already authenticated
    /// </summary>
    /// <param name="opendIdProviderUrl">OpenId Provider Url.</param>
    /// <param name="identity">Identity value.</param>
    /// <param name="claimedId">Claim identifier.</param>
    /// <param name="requiredParameters">Required Parameters.</param>
    /// <param name="optionalParameters">Optional Parameters.</param>
    /// <returns>True if login was successful.</returns>
    public static bool Login(string opendIdProviderUrl, string identity, string claimedId, string requiredParameters, string optionalParameters)
    {
        try
        {
            if (!string.IsNullOrEmpty(opendIdProviderUrl))
            {
                string redirectUrl = CreateRedirectUrl(requiredParameters, optionalParameters, claimedId, identity);
                OpenIdData data = new OpenIdData(identity);
                HttpContext.Current.Session["openid"] = data;
                HttpContext.Current.Response.Redirect(opendIdProviderUrl + redirectUrl, true);
            }
        }
        catch (Exception ex)
        {
            throw ex;

        }

        return false;
    }