/// <summary> /// Initializes a new instance of the <see cref="DuplicateProviderException"/> class. /// </summary> /// <param name="clientName">The name of the provider and client.</param> public DuplicateProviderException(ClientName clientName) { if (!String.IsNullOrEmpty(clientName.Key)) { _Message = String.Format("Provider \"{0}\" with name \"{1}\" already registered.", clientName.ProviderName, clientName.Key); } else { _Message = String.Format("Provider \"{0}\" already registered. You can use the ClientName, to register multiple clients for the same provider.", clientName); } }
/// <summary> /// Adds the specified request to the collection. /// </summary> /// <param name="key">The unique key of request.</param> /// <param name="clientName">The client name.</param> /// <param name="client">The client instance.</param> /// <param name="state">Custom state associated with authorization request.</param> public void Add(string key, ClientName clientName, OAuthBase client, object state) { if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } this.Requests.Add(key, new OAuthRequest(clientName, client, state)); this.Timer.Start(); }
/// <summary> /// Returns a string that represents the current <see cref="ClientName"/>. /// </summary> public override string ToString() { if (String.IsNullOrEmpty(this.Key)) { return(this.ProviderName); } else { return(String.Format("{0}/{1}", ClientName.Escape(this.Key), ClientName.Escape(this.ProviderName))); } }
/// <summary> /// Registers the specified client in the application. /// </summary> /// <param name="clientName">The provider name. And may also contain any client name for for division into groups.</param> /// <param name="clientId">The application identifier obtained from the provider website.</param> /// <param name="clientSecret">The application secret key obtained from the provider website.</param> /// <param name="initArgs">Additional parameters to be passed to the constructor of the client class.</param> /// <param name="scope">List of scope that will be requested from the provider. Only for OAuth 2.0.</param> /// <param name="parameters">Additional parameters that will be transferred to the provider website.</param> /// <exception cref="ArgumentNullException"><paramref name="clientName"/>, <paramref name="clientId"/> or <paramref name="clientSecret"/> is <b>null</b> or <b>empty</b>.</exception> /// <exception cref="UnknownProviderException">Provider not found by <paramref name="clientName"/>.</exception> /// <exception cref="NotSupportedException">The <paramref name="clientName"/> not suppored <paramref name="scope"/>.</exception> /// <example> /// <code lang="C#"> /// OAuthManager.RegisterClient /// ( /// "google", /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ); /// /// OAuthManager.RegisterClient /// ( /// "facebook" /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ); /// </code> /// <code lang="VB"> /// OAuthManager.RegisterClient _ /// ( /// "google", /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "facebook", /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// </code> /// <para> /// You can register multiple clients to a single provider. /// The following example shows how to do it. /// </para> /// <code lang="C#"> /// var clientName = ClientName.Create("Debug", "Facebook"); /// /// OAuthManager.RegisterClient /// ( /// clientName /// "000000000000000000", /// "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" /// ); /// /// clientName = ClientName.Create("Any name", "Facebook"); /// /// OAuthManager.RegisterClient /// ( /// clientName /// "111111111111111111", /// "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" /// ); /// </code> /// <code lang="VB"> /// Dim name As ClientName = ClientName.Create("Debug", "Facebook") /// /// OAuthManager.RegisterClient _ /// ( /// name, /// "000000000000000000", /// "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" /// ) /// /// name As ClientName = ClientName.Create("Any name", "Facebook") /// /// OAuthManager.RegisterClient _ /// ( /// name, /// "111111111111111111", /// "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" /// ) /// </code> /// </example> public static void RegisterClient(ClientName clientName, string clientId, string clientSecret, string scope = null, NameValueCollection parameters = null, object[] initArgs = null) { if (String.IsNullOrEmpty(clientName)) { throw new ArgumentNullException("clientName"); } if (String.IsNullOrEmpty(clientId)) { throw new ArgumentNullException("clientId"); } if (String.IsNullOrEmpty(clientSecret)) { throw new ArgumentNullException("clientSecret"); } // searching provider by name if (!OAuthManager.AllClients.ContainsKey(clientName.ProviderName)) { throw new UnknownProviderException("Provider [{0}] not found. Please, check provider name.", clientName.ProviderName); } // init parameters var parm = new ArrayList(); parm.Add(clientId); parm.Add(clientSecret); if (initArgs != null && initArgs.Length > 0) { parm.AddRange(initArgs); } // creating client instance OAuthBase client = Activator.CreateInstance(OAuthManager.AllClients[clientName.ProviderName], parm.ToArray()) as OAuthBase; if (!String.IsNullOrEmpty(scope)) { if (client.GetType().BaseType != typeof(OAuth2Client)) { throw new NotSupportedException("The scope supported only for OAuth 2.0 clients."); } ((OAuth2Client)client).Scope = scope; } if (parameters != null) { client.Parameters = parameters; } // add client OAuthManager.RegisterClient(clientName.Key, client); }
/// <summary> /// Registers the specified client in the application. (the main method) /// </summary> /// <param name="client">The client instance.</param> /// <param name="clientName">The any name of the client. For example: Test, Release, Project #1, Ku!, Example.org etc.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> is <b>null</b> or <b>empty</b>.</exception> /// <exception cref="DuplicateProviderException">If you attempt to register the already registered client.</exception> /// <example> /// <code lang="C#"> /// OAuthManager.RegisterClient /// ( /// "Test", /// new GoogleClient /// ( /// "00000000000000.apps.googleusercontent.com", /// "000000000000000000000000" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Test", /// new FacebookClient /// ( /// "00000000000000", /// "000000000000000000000000" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Release", /// new GoogleClient /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Release", /// new FacebookClient /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ); /// </code> /// <code lang="VB"> /// OAuthManager.RegisterClient _ /// ( /// "Test", /// New GoogleClient _ /// ( /// "00000000000000.apps.googleusercontent.com", /// "000000000000000000000000" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Test", /// New FacebookClient _ /// ( /// "00000000000000", /// "000000000000000000000000" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Release", /// New GoogleClient _ /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Release", /// New FacebookClient _ /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ) /// </code> /// </example> public static void RegisterClient(string clientName, OAuthBase client) { if (client == null) { throw new ArgumentNullException("client"); } /*if (client.ProviderName.Equals(ClientName.Parse(clientName).ProviderName, StringComparison.InvariantCultureIgnoreCase)) * { * // contains provider name * clientName = ClientName.Escape(ClientName.Parse(clientName).Key); * } * else * { * clientName = ClientName.Escape(clientName); * } * * var name = ClientName.Create(ClientName.Parse(clientName).Key ?? ClientName.Unescape(clientName), client.ProviderName); */ var name = ClientName.Create(clientName, client.ProviderName); if (OAuthManager.RegisteredClients.ContainsKey(name)) { throw new DuplicateProviderException(name); } // add client OAuthManager.RegisteredClients.Add(name, client); // remove from watching // OAuthManager.RemoveRequest(client.State.ToString()); // -- // if this is a new client if (!OAuthManager.AllClients.ContainsKey(client.ProviderName)) { // add to list OAuthManager.AllClients.Add(client.ProviderName, client.GetType()); } /*else * { * // check namespace * if (!client.GetType().Namespace.Equals("Nemiro.OAuth.Clients", StringComparison.InvariantCultureIgnoreCase)) * { * // overwrite * OAuthManager.AllClients[client.ProviderName] = client.GetType(); * } * }*/ }
/// <summary> /// Determines whether two object instances are equal. /// </summary> /// <param name="o">The object to compare with the current instance of the <see cref="ClientName"/>.</param> /// <returns><b>true</b> if the specified object is equal to the current <see cref="ClientName"/>; otherwise, <b>false</b>.</returns> public override bool Equals(object o) { if (o == null || (o.GetType() == typeof(string) && String.IsNullOrEmpty(o.ToString()))) { return(false); } if (o.GetType() == typeof(ClientName)) { return(this.Equals((ClientName)o)); } else { return(this.Equals(ClientName.Create(o.ToString()))); } }
/// <summary> /// Initializes a new instance of the <see cref="OAuthRequest"/> class. /// </summary> /// <param name="client">The instance of the OAuth client.</param> /// <param name="clientName">The client name.</param> public OAuthRequest(ClientName clientName, OAuthBase client) { /* is is not possible if (client == null) { throw new ArgumentNullException("client"); } */ if (String.IsNullOrEmpty(clientName)) { clientName = client.ProviderName; } _ClientName = clientName; _Client = client; }
/// <summary> /// Initializes a new instance of the <see cref="OAuthRequest"/> class. /// </summary> /// <param name="client">The instance of the OAuth client.</param> /// <param name="clientName">The client name.</param> public OAuthRequest(ClientName clientName, OAuthBase client) { /* is is not possible * if (client == null) * { * throw new ArgumentNullException("client"); * } */ if (String.IsNullOrEmpty(clientName)) { clientName = client.ProviderName; } _ClientName = clientName; _Client = client; }
/// <summary> /// Initializes a new instance of the <see cref="OAuthRequest"/> class. /// </summary> /// <param name="client">The instance of the OAuth client.</param> /// <param name="clientName">The client name.</param> /// <param name="state">Custom state associated with the request.</param> public OAuthRequest(ClientName clientName, OAuthBase client, object state) { if (client == null) { throw new ArgumentNullException("client"); } if (String.IsNullOrEmpty(clientName)) { clientName = client.ProviderName; } this.ClientName = clientName; this.Client = client; this.DateCreated = DateTime.Now; this.State = state; }
/// <summary> /// Returns the authorization URL of the specified provider, query parameters and return URL. /// </summary> /// <param name="clientName"> /// The provider name, through which it is necessary to authorize the current user; or the name of the registered client. /// </param> /// <param name="parameters">Additional parameters to be passed to the authorization URL.</param> /// <param name="returnUrl">The address to which the user is redirected after the authorization.</param> /// <param name="state">Custom state associated with authorization request.</param> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> public static string GetAuthorizationUrl(ClientName clientName, NameValueCollection parameters, string returnUrl, object state) { if (!OAuthManager.RegisteredClients.ContainsKey(clientName)) { throw new ClientIsNotRegisteredException(); } // get normal client name clientName = OAuthManager.RegisteredClients.Keys.First(k => k == clientName); // create new instance of the client var client = OAuthManager.RegisteredClients[clientName].Clone(parameters, returnUrl); // add request OAuthManager.AddRequest(client.State, clientName, client, state); // return url return(client.AuthorizationUrl); }
/// <summary> /// Returns the authorization URL of the specified provider with specified parameters. /// </summary> /// <param name="clientName">Provider name, through which it is necessary to authorize the current user.</param> /// <param name="parameters">Additional parameters to be passed to the authorization URL.</param> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> public static string GetAuthorizationUrl(string clientName, NameValueCollection parameters) { return(OAuthWeb.GetAuthorizationUrl(ClientName.Parse(clientName), parameters, null, null)); }
/// <summary> /// Returns the authorization URL of the specified provider. /// </summary> /// <param name="clientName">Provider name, through which it is necessary to authorize the current user.</param> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> public static string GetAuthorizationUrl(string clientName) { return(OAuthWeb.GetAuthorizationUrl(ClientName.Parse(clientName), null, null, null)); }
/// <summary> /// Redirects current client to the authorization page of the specified provider, query parameters and return URL. /// </summary> /// <param name="clientName">Provider name, through which it is necessary to authorize the current user.</param> /// <param name="returnUrl">The address to which the user is redirected after the authorization.</param> /// <param name="parameters">Additional parameters to be passed to the authorization query.</param> /// <exception cref="ClientIsNotRegisteredException"> /// <paramref name="clientName"/> is unregistered. Use the <see cref="OAuthManager.RegisterClient(OAuthBase)" /> for OAuth clients registration. /// </exception> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> /// <remarks> /// <para>The method will not work in desktop applications. For desktop applications you can use <see cref="GetAuthorizationUrl(string, NameValueCollection, string)"/>.</para> /// </remarks> /// <seealso cref="GetAuthorizationUrl(ClientName, NameValueCollection, string)"/> public static void RedirectToAuthorization(ClientName clientName, NameValueCollection parameters, string returnUrl) { OAuthWeb.RedirectToAuthorization(clientName, parameters, returnUrl, null); }
/// <summary> /// Initializes a new instance of the <see cref="OAuthRequest"/> class. /// </summary> /// <param name="client">The instance of the OAuth client.</param> /// <param name="clientName">The client name.</param> public OAuthRequest(ClientName clientName, OAuthBase client) : this(clientName, client, null) { }
/// <summary> /// Adds the specified request to the collection. /// </summary> /// <param name="key">The unique request key.</param> /// <param name="clientName">The client name.</param> /// <param name="client">The client instance.</param> /// <param name="state">Custom state associated with authorization request.</param> internal static void AddRequest(string key, ClientName clientName, OAuthBase client, object state) { OAuthManager.RequestsProvider.Add(key, clientName, client, state); }
/// <summary> /// Registers the specified client in the application. /// </summary> /// <param name="providerName">The provider name.</param> /// <param name="clientId">The application identifier obtained from the provider website.</param> /// <param name="clientSecret">The application secret key obtained from the provider website.</param> /// <param name="scope">List of scope that will be requested from the provider. Only for OAuth 2.0.</param> /// <param name="initArgs">Additional parameters to be passed to the constructor of the client class.</param> /// <param name="parameters">Additional parameters that will be transferred to the provider website.</param> /// <exception cref="ArgumentNullException"><paramref name="providerName"/>, <paramref name="clientId"/> or <paramref name="clientSecret"/> is <b>null</b> or <b>empty</b>.</exception> /// <exception cref="UnknownProviderException">Provider not found by <paramref name="providerName"/>.</exception> /// <exception cref="NotSupportedException">The <paramref name="providerName"/> not suppored <paramref name="scope"/>.</exception> /// <example> /// <code lang="C#"> /// OAuthManager.RegisterClient /// ( /// "google", /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ); /// /// OAuthManager.RegisterClient /// ( /// "facebook" /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ); /// </code> /// <code lang="VB"> /// OAuthManager.RegisterClient _ /// ( /// "google", /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "facebook", /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// </code> /// </example> public static void RegisterClient(string providerName, string clientId, string clientSecret, string scope = null, NameValueCollection parameters = null, object[] initArgs = null) { OAuthManager.RegisterClient(ClientName.Parse(providerName), clientId, clientSecret, scope, parameters, initArgs); }
/// <summary> /// Determines whether two object instances are equal. /// </summary> /// <param name="value">The instance of <see cref="ClientName"/> to compare with the current instance of the <see cref="ClientName"/>.</param> /// <returns><b>true</b> if the specified <see cref="ClientName"/> instance is equal to the current <see cref="ClientName"/>; otherwise, <b>false</b>.</returns> public bool Equals(ClientName value) { return this.Hash.Equals(value.Hash, StringComparison.InvariantCultureIgnoreCase); }
/// <summary> /// Adds the specified request to the collection. /// </summary> /// <param name="key">The unique request key.</param> /// <param name="clientName">The client name.</param> /// <param name="client">The client instance.</param> internal static void AddRequest(string key, ClientName clientName, OAuthBase client) { OAuthManager.Requests.Add(key, new OAuthRequest(clientName, client)); _Timer.Start(); }
/// <summary> /// Checks registered provider with the specified name or not. /// </summary> /// <param name="clietName">The provider name or client name.</param> public static bool IsRegisteredClient(ClientName clietName) { if (String.IsNullOrEmpty(clietName)) { throw new ArgumentNullException("clietName"); } return OAuthManager.RegisteredClients.ContainsKey(clietName); }
/// <summary> /// Returns the authorization URL of the specified provider, query parameters and return URL. /// </summary> /// <param name="clientName"> /// The provider name, through which it is necessary to authorize the current user; or the name of the registered client. /// </param> /// <param name="parameters">Additional parameters to be passed to the authorization URL.</param> /// <param name="returnUrl">The address to which the user is redirected after the authorization.</param> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> public static string GetAuthorizationUrl(ClientName clientName, NameValueCollection parameters, string returnUrl) { if (!OAuthManager.RegisteredClients.ContainsKey(clientName)) { throw new ClientIsNotRegisteredException(); } // get normal client name clientName = OAuthManager.RegisteredClients.Keys.First(k => k == clientName); // create new instance of the client var client = OAuthManager.RegisteredClients[clientName].Clone(parameters, returnUrl); // add request OAuthManager.AddRequest(client.State, clientName, client); // return url return client.AuthorizationUrl; }
/// <summary> /// Returns the authorization URL of the specified provider and return URL. /// </summary> /// <param name="clientName">Provider name, through which it is necessary to authorize the current user.</param> /// <param name="returnUrl">The address to which the user is redirected after the authorization.</param> /// <param name="state">Custom state associated with authorization request.</param> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> public static string GetAuthorizationUrl(string clientName, string returnUrl, object state) { return(OAuthWeb.GetAuthorizationUrl(ClientName.Parse(clientName), null, returnUrl, state)); }
/// <summary> /// Returns the authorization URL of the specified provider, query parameters and return URL. /// </summary> /// <param name="clientName"> /// The provider name, through which it is necessary to authorize the current user; or the name of the registered client. /// </param> /// <param name="parameters">Additional parameters to be passed to the authorization URL.</param> /// <param name="returnUrl">The address to which the user is redirected after the authorization.</param> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> public static string GetAuthorizationUrl(ClientName clientName, NameValueCollection parameters, string returnUrl) { return(OAuthWeb.GetAuthorizationUrl(clientName, parameters, returnUrl, null)); }
/// <summary> /// Registers the specified client in the application. /// </summary> /// <param name="client">The client instance.</param> /// <param name="clientName">The any name of the client. For example: Test, Release, Project #1, Ku!, Example.org etc.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> is <b>null</b> or <b>empty</b>.</exception> /// <exception cref="DuplicateProviderException">If you attempt to register the already registered client.</exception> /// <example> /// <code lang="C#"> /// OAuthManager.RegisterClient /// ( /// "Test", /// new GoogleClient /// ( /// "00000000000000.apps.googleusercontent.com", /// "000000000000000000000000" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Test", /// new FacebookClient /// ( /// "00000000000000", /// "000000000000000000000000" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Release", /// new GoogleClient /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Release", /// new FacebookClient /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ); /// </code> /// <code lang="VB"> /// OAuthManager.RegisterClient _ /// ( /// "Test", /// New GoogleClient _ /// ( /// "00000000000000.apps.googleusercontent.com", /// "000000000000000000000000" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Test", /// New FacebookClient _ /// ( /// "00000000000000", /// "000000000000000000000000" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Release", /// New GoogleClient _ /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Release", /// New FacebookClient _ /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ) /// </code> /// </example> public static void RegisterClient(ClientName clientName, OAuthBase client) { OAuthManager.RegisterClient(clientName.Key, client); }
/// <summary> /// Adds the specified request to the collection. /// </summary> /// <param name="key">The unique request key.</param> /// <param name="clientName">The client name.</param> /// <param name="client">The client instance.</param> internal static void AddRequest(string key, ClientName clientName, OAuthBase client) { OAuthManager.AddRequest(key, clientName, client, null); }
/// <summary> /// Redirects current client to the authorization page of the specified provider. /// </summary> /// <param name="clientName">Provider name, through which it is necessary to authorize the current user.</param> /// <exception cref="ClientIsNotRegisteredException"> /// <paramref name="clientName"/> is unregistered. Use the <see cref="OAuthManager.RegisterClient(OAuthBase)" /> for OAuth clients registration. /// </exception> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> /// <remarks> /// <para>The method will not work in desktop applications. For desktop applications you can use <see cref="GetAuthorizationUrl(string)"/>.</para> /// </remarks> /// <seealso cref="GetAuthorizationUrl(string)"/> public static void RedirectToAuthorization(string clientName) { OAuthWeb.RedirectToAuthorization(ClientName.Parse(clientName), null, null, null); }
/// <summary> /// Redirects current client to the authorization page of the specified provider with specified parameters. /// </summary> /// <param name="clientName">Provider name, through which it is necessary to authorize the current user.</param> /// <param name="parameters">Additional parameters to be passed to the authorization query.</param> /// <exception cref="ClientIsNotRegisteredException"> /// <paramref name="clientName"/> is unregistered. Use the <see cref="OAuthManager.RegisterClient(OAuthBase)" /> for OAuth clients registration. /// </exception> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> /// <remarks> /// <para>The method will not work in desktop applications. For desktop applications you can use <see cref="GetAuthorizationUrl(string, NameValueCollection)"/>.</para> /// </remarks> /// <seealso cref="GetAuthorizationUrl(string, NameValueCollection)"/> public static void RedirectToAuthorization(string clientName, NameValueCollection parameters) { OAuthWeb.RedirectToAuthorization(ClientName.Parse(clientName), parameters, null, null); }
/// <summary> /// Registers the specified client in the application. /// </summary> /// <param name="providerName">The provider name.</param> /// <param name="clientId">The application identifier obtained from the provider website.</param> /// <param name="clientSecret">The application secret key obtained from the provider website.</param> /// <exception cref="ArgumentNullException"><paramref name="providerName"/>, <paramref name="clientId"/> or <paramref name="clientSecret"/> is <b>null</b> or <b>empty</b>.</exception> /// <exception cref="UnknownProviderException">Provider not found by <paramref name="providerName"/>.</exception> /// <example> /// <code lang="C#"> /// OAuthManager.RegisterClient /// ( /// "google", /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ); /// /// OAuthManager.RegisterClient /// ( /// "facebook" /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ); /// </code> /// <code lang="VB"> /// OAuthManager.RegisterClient _ /// ( /// "google", /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "facebook", /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// </code> /// </example> public static void RegisterClient(string providerName, string clientId, string clientSecret) { OAuthManager.RegisterClient(ClientName.Parse(providerName), clientId, clientSecret, null, null, null); }
/// <summary> /// Redirects current client to the authorization page of the specified provider and return URL. /// </summary> /// <param name="clientName">Provider name, through which it is necessary to authorize the current user.</param> /// <param name="returnUrl">The address to which the user is redirected after the authorization.</param> /// <param name="state">Custom state associated with authorization request.</param> /// <exception cref="ClientIsNotRegisteredException"> /// <paramref name="clientName"/> is unregistered. Use the <see cref="OAuthManager.RegisterClient(OAuthBase)" /> for OAuth clients registration. /// </exception> /// <exception cref="NullHttpContextException"> /// The exception that is thrown when you try to access methods that are designed for web projects. /// </exception> /// <remarks> /// <para>The method will not work in desktop applications. For desktop applications you can use <see cref="GetAuthorizationUrl(string, string)"/>.</para> /// </remarks> /// <seealso cref="GetAuthorizationUrl(string, string, object)"/> public static void RedirectToAuthorization(string clientName, string returnUrl, object state) { OAuthWeb.RedirectToAuthorization(ClientName.Parse(clientName), null, returnUrl, state); }
/// <summary> /// Determines whether two object instances are equal. /// </summary> /// <param name="value">The instance of <see cref="ClientName"/> to compare with the current instance of the <see cref="ClientName"/>.</param> /// <returns><b>true</b> if the specified <see cref="ClientName"/> instance is equal to the current <see cref="ClientName"/>; otherwise, <b>false</b>.</returns> public bool Equals(ClientName value) { return(this.Hash.Equals(value.Hash, StringComparison.InvariantCultureIgnoreCase)); }