示例#1
0
        protected void createAndSendLoginRequest(DossiaOpenID dossiaOpenID, 
            OpenIdClient openIdClient, 
            Boolean reqAttributes,
            Boolean reqOauthToken)
        {
            dossiaOpenID.InitializeForSending(openIdClient);
            
            // see http://docs.dossia.org/index.php/Dossia_OpenID_Consumer_Developer_Guide#Attributes_Available_via_OpenID
            // for list of available attributes
            if (reqAttributes)
            {
                AttributeExchange attributeExchange = new AttributeExchange(openIdClient);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/address1", "address1", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/address2", "address2", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/city", "city", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/dateOfBirth", "dateOfBirth", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/email", "email", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/employeeId", "employeeId", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/employer", "employer", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/firstName", "firstName", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/gender", "gender", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/lastName", "lastName", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/middleName", "middleName", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/postalCode", "postalCode", 1, true);
                attributeExchange.AddFetchItem("http://openid.dossia.org/participant/state", "state", 1, true);
            }

            if (reqOauthToken)
            {
                OAuthClient oauthClient = DossiaOauth.createDossiaOAuthClient();
                OAuthExtension oauthext = new OAuthExtension(openIdClient, oauthClient);
            }

            openIdClient.CreateRequest(false, true);
        }
 protected void createAndSendLoginRequest(DossiaOpenID dossiaOpenID, OpenIdClient openIdClient)
 {
     dossiaOpenID.InitializeForSending(openIdClient);
     AttributeExchange attributeExchange = new AttributeExchange(openIdClient);
     // see http://docs.dossia.org/index.php/Dossia_OpenID_Consumer_Developer_Guide#Attributes_Available_via_OpenID
     // for list of available attributes
     attributeExchange.AddFetchItem("http://openid.dossia.org/participant/firstName", "firstName", 1, true);
     attributeExchange.AddFetchItem("http://openid.dossia.org/participant/lastName", "lastName", 1, true);
     
     openIdClient.CreateRequest(false, true);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            // If this is not a postback, start up the Consumer
            // and handle any OpenID response messages, if present
            if (!IsPostBack)
            {
                DossiaOpenID dossiaOpenID = new DossiaOpenID(Application, Session);
                OpenIdClient openIdClient = dossiaOpenID.CreateOpenIdClient();
                // Read the arguments in the current request and
                // automatically validate any OpenID responses,
                // firing events when actions occur.
                openIdClient.ValidationSucceeded += new EventHandler(openid_ValidationSucceeded);
                openIdClient.ValidationFailed += new EventHandler(openid_ValidationFailed);
                openIdClient.ReceivedCancel += new EventHandler(openid_ReceivedCancel);
                // Subscribing to SetupNeeded is only needed if using immediate authentication
                openIdClient.ReceivedSetupNeeded += new EventHandler(openid_SetupNeeded); 
                openIdClient.DetectAndHandleResponse();

                // if there were no events to handle, just call getLoginInfo
                createAndSendLoginRequest(dossiaOpenID, openIdClient);
            }
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Boolean reqAttributes = Request["reqAttributes"] == "1";
            Boolean reqOauthToken = Request["reqOauthToken"] == "1";
            Trace.Write("reqAttributes = '" + reqAttributes + "'");
            Trace.Write("reqOauthToken = '" + reqOauthToken + "'");
            
            // If this is not a postback, start up the Consumer
            // and handle any OpenID response messages, if present
            if (!IsPostBack)
            {
                DossiaOpenID dossiaOpenID = new DossiaOpenID(Application, Session);
                OpenIdClient openIdClient = dossiaOpenID.CreateOpenIdClient();
                // Read the arguments in the current request and
                // automatically validate any OpenID responses,
                // firing events when actions occur.
                openIdClient.ValidationSucceeded += new EventHandler(openid_ValidationSucceeded);
                openIdClient.ValidationFailed += new EventHandler(openid_ValidationFailed);
                openIdClient.ReceivedCancel += new EventHandler(openid_ReceivedCancel);
                // Subscribing to SetupNeeded is only needed if using immediate authentication
                openIdClient.ReceivedSetupNeeded += new EventHandler(openid_SetupNeeded);
                openIdClient.DetectAndHandleResponse();

                // DetectAndHandleResponse does not handle errors, so we'll do it.
                if (RequestedMode.Error.Equals(openIdClient.RequestedMode))
                {
                    String error = openIdClient.StateContainer.RequestArguments["openid.error"];
                    Trace.Write("Got openid error: '" + error + "'");
                    Response.Redirect("Default.aspx?error=" + Server.UrlEncode(error)); 
                }
                else
                {
                    // if there were no events to handle, just call getLoginInfo
                    createAndSendLoginRequest(dossiaOpenID, openIdClient, reqAttributes, reqOauthToken);
                }
            }
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LoginInfo loginInfo = (LoginInfo)Session["loginInfo"];
            if (loginInfo != null)
            {
                openID = loginInfo.openID;
                accessToken = loginInfo.accessToken;
            }
            else
            {
                openID = null;
                accessToken = null;
            }
            restUrl = Request["restUrl"];
            if (restUrl == null || "".Equals(restUrl.Trim()))
            {
                restUrl = ConfigurationManager.AppSettings["rest.api.url"];
            }
            String restCallSubmit = Request["OauthSubmit"];
            if (restCallSubmit != null && !"".Equals(restCallSubmit.Trim()))
            {
                HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(new Uri(restUrl));
                wr.Method = "GET";
                OAuthClient oac = DossiaOauth.createDossiaOAuthClient();
                wr.Credentials = oac.GetCredentials(accessToken, null);
                wr.AllowAutoRedirect = false;
                WebResponse response = wr.GetResponse();
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    restResponse = sr.ReadToEnd();
                    restResponse = Server.HtmlEncode(restResponse);
                }
            }
            String ssoSubmit = Request["SsoSubmit"];
            if (ssoSubmit != null && !"".Equals(ssoSubmit.Trim()))
            {
                String ssoRequestTokenUrl = ConfigurationManager.AppSettings["authserver.sso.token.url"];
                HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(new Uri(ssoRequestTokenUrl));
                wr.Method = "GET";
                OAuthClient oac = DossiaOauth.createDossiaOAuthClient();
                wr.Credentials = oac.GetCredentials(accessToken, null);
                wr.AllowAutoRedirect = false;
                WebResponse response = wr.GetResponse();
                String token;
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    token = sr.ReadToEnd();
                }


                // ok now we have a token, let's create a checkid_setup request. 
                // The token is valid for two minutes, and can only be used once.
                // Further, Dossia requires that the openid you setup in the
                // checkid_setup request matches the user who has requested the token.
                // Further, there must be a session active for this user on the authserver.
                // Sessions can be kept alive using the url
                // ${AUTHSERVER_BASE_URL}/authserver/

                DossiaOpenID dossiaOpenID = new DossiaOpenID(Application, Session);
                OpenIdClient openIdClient = dossiaOpenID.CreateOpenIdClient();

                openIdClient.Identity = loginInfo.openID;
                AttributeExchange attributeExchange = new AttributeExchange(openIdClient);
                attributeExchange.Mode = AttributeExchangeMode.Store;
                attributeExchange.AddStoreItem("http://openid.dossia.org/sso/ssoToken", "ssoToken", token);

                // Read the arguments in the current request and
                // automatically validate any OpenID responses,
                // firing events when actions occur.
                openIdClient.ValidationSucceeded += new EventHandler(openid_ValidationSucceeded);
                openIdClient.ValidationFailed += new EventHandler(openid_ValidationFailed);
                openIdClient.ReceivedCancel += new EventHandler(openid_ReceivedCancel);
                // Subscribing to SetupNeeded is only needed if using immediate authentication
                openIdClient.ReceivedSetupNeeded += new EventHandler(openid_SetupNeeded);
                openIdClient.DetectAndHandleResponse();

                // DetectAndHandleResponse does not handle errors, so we'll do it.
                if (RequestedMode.Error.Equals(openIdClient.RequestedMode))
                {
                    String error = openIdClient.StateContainer.RequestArguments["openid.error"];
                    Trace.Write("Got openid error: '" + error + "'");
                    Response.Redirect("Default.aspx?error=" + Server.UrlEncode(error));
                }
                else
                {
                    // if there were no events to handle, just call getLoginInfo
                    createAndSendLoginRequest(dossiaOpenID, openIdClient);
                }

            }
        }
示例#6
0
 protected void createAndSendLoginRequest(DossiaOpenID dossiaOpenID,
     OpenIdClient openIdClient)
 {
     dossiaOpenID.InitializeForSending(openIdClient);
     openIdClient.CreateRequest(false, true);
 }