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); }
public OpenIdClient CreateOpenIdClient() { OpenIdClient returnValue = new OpenIdClient(); returnValue.EnableStatefulMode(associationManager, sessionManager); // todo: make this a property returnValue.Identity = System.Configuration.ConfigurationManager.AppSettings["openid.default.openid"]; return returnValue; }
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 OpenIdClient GetConsumer() { // Initialize a new OpenIdClient, reading arguments // from the current request, and using Session and // Application objects to store data. For more // flexibility, see "Disabling Stateful Mode" and // "Persisting Stateful Data" below for more information. OpenIdClient openid = new OpenIdClient(); openid.EnableStatefulMode(associationManager, sessionManager); // Subscribe to all the events that could occur openid.ValidationSucceeded += new EventHandler(openid_ValidationSucceeded); openid.ValidationFailed += new EventHandler(openid_ValidationFailed); openid.ReceivedCancel += new EventHandler(openid_ReceivedCancel); // Subscribing to SetupNeeded is only needed if using immediate authentication openid.ReceivedSetupNeeded += new EventHandler(openid_SetupNeeded); return openid; }
public IUser GetOrCreateUserIfCorrectFormOfIdentity(string identity) { if (identity.StartsWith("http://") || identity.StartsWith("https://")) { NameValueCollection openIdClientArgs = new NameValueCollection(); OpenIdClient openIdClient = new OpenIdClient(openIdClientArgs); openIdClient.Identity = identity; openIdClient.TrustRoot = null; openIdClient.ReturnUrl = new Uri(string.Format("http://{0}", FileHandlerFactoryLocator.HostnameAndPort)); // The proper identity is encoded in the URL Uri requestUri = openIdClient.CreateRequest(false, false); if (openIdClient.ErrorState == ErrorCondition.NoErrors) if (openIdClient.IsValidIdentity()) { RequestParameters openIdRequestParameters = new RequestParameters(requestUri.Query.Substring(1)); identity = openIdRequestParameters["openid.identity"]; return GetOrCreateUser(identity); } } return null; }
/// <summary> /// Create a new instance of OpenIdDesktopClient. /// </summary> /// <param name="identity">The OpenID Identity to authenticate.</param> /// <param name="timeout">The amount of time to wait for a response back from the OpenID Provider.</param> /// <param name="hostName">The hostname that will be used for the return URL.</param> /// <param name="port">The port number that should be used to receive the authentication response from the User's web browser, if random ports are not desired.</param> public OpenIdDesktopClient(string identity, int timeout, string hostName, int port) { Init(identity); _Hostname = hostName; _Timeout = timeout; _Port = port; openid = GetConsumer(new NameValueCollection()); }
/// <summary> /// Dispose all resources. /// </summary> /// <param name="disposing">If true, dispose both managed and unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { openid = null; _SessionManager = null; _AssociationManager = null; } if (listener != null) { listener.Close(); } }
/// <summary> /// The callback method for the temporary HTTP server. /// </summary> /// <param name="result">The <see cref="IAsyncResult"/> object representing the active <see cref="HttpListener"/>.</param> void ListenerCallback(IAsyncResult result) { HttpListener listener = (HttpListener)result.AsyncState; if (!listener.IsListening) { return; } try { // Call EndGetContext to complete the asynchronous operation. HttpListenerContext context = listener.EndGetContext(result); HttpListenerRequest request = context.Request; openid = GetConsumer(request.QueryString); openid.ValidationSucceeded += new EventHandler(openid_ValidationSucceeded); openid.ValidationFailed += new EventHandler(openid_ValidationFailed); openid.ReceivedCancel += new EventHandler(openid_ReceivedCancel); openid.DetectAndHandleResponse(); // Obtain a response object. HttpListenerResponse response = context.Response; // Construct a response. string responseString = "<HTML><BODY onLoad=\"javascript:window.close();\">Please close this browser window.</BODY></HTML>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); responsereceived = true; listener.Close(); if (AuthenticationResponseReceived != null) { AuthenticationResponseReceived.Invoke(this, new EventArgs()); } } catch (HttpListenerException e) { Tracer.Write("HttpListener error: " + e.Message); } }
/// <summary> /// Create a new OpenIdClient object with settings appropriate for this class. /// </summary> /// <param name="arguments">The <see cref="NameValueCollection"/> containing the received arguments.</param> /// <returns>The created OpenIdClient object.</returns> OpenIdClient GetConsumer(NameValueCollection arguments) { openid = new OpenIdClient(arguments); if (_StatefulMode) { openid.EnableStatefulMode(_AssociationManager, _SessionManager); } openid.Identity = _Identity; if (_DirectedProviderUrl != null) { openid.UseDirectedIdentity = true; openid.ProviderUrl = _DirectedProviderUrl; } SetConsumerUrls(); return openid; }
/// <summary> /// Create a new instance of OpenIdDesktopClient. /// </summary> /// <param name="identity">The OpenID Identity to authenticate.</param> /// <param name="timeout">The amount of time to wait for a response back from the OpenID Provider.</param> /// <param name="hostName">The hostname that will be used for the return URL.</param> /// <param name="lowPort">The lowest port number in the desired range.</param> /// <param name="highPort">The highest port number in the desired range.</param> /// <remarks> /// Use a random port between two supplied port numbers. /// </remarks> public OpenIdDesktopClient(string identity, int timeout, string hostName, int lowPort, int highPort) { _lowPort = lowPort; _highPort = highPort; _UseRandomPort = true; Init(identity); _Hostname = hostName; _Timeout = timeout; openid = GetConsumer(new NameValueCollection()); }
/// <summary> /// Create a new instance of OpenIdDesktopClient. /// </summary> /// <param name="identity">The OpenID Identity to authenticate.</param> /// <param name="timeout">The amount of time to wait for a response back from the OpenID Provider.</param> public OpenIdDesktopClient(string identity, int timeout) { _UseRandomPort = true; Init(identity); _Timeout = timeout; openid = GetConsumer(new NameValueCollection()); }
/// <summary> /// Creates a new instance of AXReceiver. /// </summary> /// <param name="arguments">A collection of arguments received from a request.</param> public AXReceiver(NameValueCollection arguments) { openid = new OpenIdClient(arguments); ax = new AttributeExchange(openid); }
/// <summary> /// Creates a new instance of AXReceiver. /// </summary> public AXReceiver() { openid = new OpenIdClient(); ax = new AttributeExchange(openid); }
public void InitializeForSending(OpenIdClient openIdClient) { openIdClient.TrustRoot = System.Configuration.ConfigurationManager.AppSettings["openid.realm"]; }
protected void createAndSendLoginRequest(DossiaOpenID dossiaOpenID, OpenIdClient openIdClient) { dossiaOpenID.InitializeForSending(openIdClient); openIdClient.CreateRequest(false, true); }